c++定义:
typedef struct _GLYMODE{
unsigned int dwLockStatus;
unsigned int dwModeStatus;
}GLYMODE, *LPGLYMODE;
int GLY_DeGetMode(GLYHANDLE h, LPGLYMODE* lppDEModeData);
c# 转换:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
public struct GlyMode
{
public uint dwLockStatus;
public uint dwModeStatus;
}
[DllImport(@"libglyde.dll", EntryPoint = "GLY_DeGetMode", CallingConvention = CallingConvention.Cdecl)]
public static extern int GLY_DeGetMode(int handle, IntPtr glyDeModeData);
我的问题是: 在方法import的时,方法参数我转换的对吗?还是写成:public static extern int GLY_DeGetMode(int handle, ref GlyMode glyDeModeData);
请高手帮忙,谢谢
问题已经解决
[DllImport(@"libglyde.dll", EntryPoint = "GLY_DeGetMode", CallingConvention = CallingConvention.Cdecl)]
public static extern int GLY_DeGetMode(int handle, ref IntPtr glyDeModeData);
可以使用工具自动生成对非托管动态库函数与结构的声明,搜索工具CLRInsideOut。