急!C#调用DLL函数,有个结果取不到,是怎么回事?请知秋一叶等大侠帮忙。
njzc 2002-05-29 01:29:09 C写的DLL中,函数int FunctionA(int nNum,StructA *pStructA);
StructA
{
int nAge;
char cName[20];
char cClass[10];
char cFlag;
};
我在C#中声明,
[StructLayout(LayoutKind.Sequential)]
public struct StructA
{
public int nAge;
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=20 )]
public string cName;
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=10 )]
public string cClass;
public int cFlag;
}
[DllImport("..\\..\\lib\\MyDll.dll",EntryPoint="FunctionA")]
public static extern int FunctionA(int nNum,[In,Out] ref StructA structA);
调用:
StructA structA=new StructA();
int nNum=0;
int a=FunctionA(nNum,ref structA);
现在问题是调用的时候,除了cClass,其他值都可以取到,我取出来的cClass是个空字符串,这个是怎么回事?该如何解决?急!