我在非托管 C/C++ 代码 (dll) 中有一个函数,它返回一个包含 char 数组的结构。我创建了 C# 结构来在调用函数时接收这个返回值。在调用这个函数时,我得到'System.Runtime.InteropServices.MarshalDirectiveException'
这是 C 声明:
typedef struct T_SAMPLE_STRUCT {
int num;
char text[20];
} SAMPLE_STRUCT;
SAMPLE_STRUCT sampleFunction( SAMPLE_STRUCT ss );
这是 C# 声明:
struct SAMPLE_STRUCT
{
public int num;
public string text;
}
class Dllwrapper
{
[DllImport("samplecdll.dll")]
public static extern SAMPLE_STRUCT sampleFunction(SAMPLE_STRUCT ss);
}
我正在使用 1 字节的 ASCII。
有没有人有关于如何做到这一点的提示或解决方案?