w**w 发帖数: 5391 | 1 in .NET, i defined a function in C++ class library for file open
int open(char* filename) {blah...}
Now i want to use it in C#, add reference from this DLL. C# asks:
open(sbyte*)
how to use this function in C#, where to convert a string to sbyte* ?
thanks. | y****t 发帖数: 10233 | 2 it is not safe code, i think.
【在 w**w 的大作中提到】 : in .NET, i defined a function in C++ class library for file open : int open(char* filename) {blah...} : Now i want to use it in C#, add reference from this DLL. C# asks: : open(sbyte*) : how to use this function in C#, where to convert a string to sbyte* ? : thanks.
| w**w 发帖数: 5391 | 3 the problem is how to convert it. it is impossible for everyone to rewrite the
previous code, i suppose .NET should be able to handle it.
【在 y****t 的大作中提到】 : it is not safe code, i think.
| s*i 发帖数: 5025 | 4 try this:
//in C#, make a sbyte array, say
//sbyte[] sArray = .....
unsafe
{
fixed(byte *fileName=sArray) className.open(fileName);
}
This should work. Remember to enable 'unsafe blocks" in Visual Studio to
compile correctly.
Working with sbyte is actually not very convinient. If you can recompile your
C++ with "/J" (default char unsigned: Yes), your expected input becomes
"byte*" instead of "sbyte*". This way, you can try this:
//using System.Text
.....
ASCIIEncoding encoding=new ASCIIEncod
【在 w**w 的大作中提到】 : in .NET, i defined a function in C++ class library for file open : int open(char* filename) {blah...} : Now i want to use it in C#, add reference from this DLL. C# asks: : open(sbyte*) : how to use this function in C#, where to convert a string to sbyte* ? : thanks.
| w**w 发帖数: 5391 | 5 thanks a lot!! The second method works. I had troubles to convert sbyte, so i
didn't try first one, but it looks fine as well.
【在 s*i 的大作中提到】 : try this: : //in C#, make a sbyte array, say : //sbyte[] sArray = ..... : unsafe : { : fixed(byte *fileName=sArray) className.open(fileName); : } : This should work. Remember to enable 'unsafe blocks" in Visual Studio to : compile correctly. : Working with sbyte is actually not very convinient. If you can recompile your
|
|