<分区>
Possible Duplicate:
Passing char pointer from C# to c++ function
我有这样的问题:
我有一个带有此签名的 C++ 函数:
int myfunction ( char* Buffer, int * rotation)
缓冲区参数必须用空格字符(0x20 hex)填充
在 C++ 中,我可以简单地解决这个问题:
char* buffer = (char *)malloc(256);
memset(buffer,0x20,256);
res = myfunction (buffer, rotation);
我正在尝试从 C# 调用此函数。
这是我的 p/invoke 声明:
[DllImport("mydll.dll", CharSet = CharSet.Ansi, SetLastError = true)]
private static extern unsafe int myfunction (StringBuilder Buffer, int* RotDegree);
在我的 C# 类(class)中,我尝试这样做:
StringBuilder buffer = new StringBuilder(256);
buffer.Append(' ', 256);
...
myfunction(buffer, rotation);
但它不起作用......
谁能帮帮我?
谢谢。