C#调用Dll出错(有关结构体) 资料也好难查
用C++代码生成的 DLL 被.net的C#调用
C++代码
#define WIN32API __declspec(dllexport)
typedef struct PPP
{
unsigned char a[10];
unsigned int b;
};
PPP ppp;
extern "C"
WIN32API
void SetPPP(PPP p)
{
ppp=p;
}
extern "C"
WIN32API
PPP GetPPP()
{
return ppp;
}
请问如何写C#调用代码?
下面是我自己写的,但是总是有问题
[StructLayout(LayoutKind.Sequential)]
public struct PPP
{
[MarshalAs(UnmanagedType.???(不知道写什么),SizeConst = 10)]
public Byte[] a;
public int b;
}
[DllImport("Center.dll", ExactSpelling = true)]
public static extern void SetPPP(PPP p);
[DllImport("Center.dll", ExactSpelling = true)]
public static extern PPP GetPPP();
请问如何写正确?
------解决方案--------------------
那就改成这样
extern "C"
WIN32API
void GetPPP(PPP *p)
{
PPP *P=ppp;
}
[DllImport("Center.dll", ExactSpelling = true)]
public static extern void GetPPP(ref PPP p);
------解决方案--------------------http://topic.csdn.net/u/20100126/13/8bb52c6b-165e-4d32-8691-bc97f7126adc.html