[英]Try Call Dll, But the method has a complicated struct type, I can't define it in .Net
C ++中的结构定义为:
typedef struct _DEVICE_PATH_LIST_
{
int NumDevice;
TCHAR *devicePath[DEVICE_PATH_LIST_SIZE];
} DEVICE_PATH_LIST;
C ++函数的定义是:
LandiWin_iGetDevicePathList( int iDeviceType, DEVICE_PATH_LIST * devicePathList);
然后,我想调用该方法,因此需要定义一个可以表示DEVICE_PATH_LIST
的结构。 这是我在C#中的定义:
[StructLayout(LayoutKind.Sequential)]
public unsafe struct DevicePathType
{
public int NumDevice;
[MarshalAs(UnmanagedType.ByValArray,SizeConst=32)]
public char*[] devicePath;
}
但这是不对的,我也尝试了所有其他类型,但都失败了。 请帮助我定义一个正确的结构。
C ++的代码如下:
typedef struct _DEVICE_PATH_LIST_
{
int NumDevice;
TCHAR *devicePath[DEVICE_PATH_LIST_SIZE];
} DEVICE_PATH_LIST;
C#的代码需要像这样:
[StructLayout(LayoutKind.Sequential)]
public struct DevicePathType
{
public int NumDevice;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public IntPtr[] devicePath;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.