如何使用不同语言定义的DLL接口呢?
来源:百度知道 编辑:UC知道 时间:2024/07/15 23:43:00
比如说
DLL定一个了一个C++接口的方法:
void function(wchar_t *pszPage);
在C#的程序里调用这个方法,可是C#根本不认wchar_t类型阿
DLL定一个了一个C++接口的方法:
void function(wchar_t *pszPage);
在C#的程序里调用这个方法,可是C#根本不认wchar_t类型阿
举个例子:你要调用user32.dll中的GetCursorPos(),在C中的原形是
BOOL GetCursorPos(LPPOINT lpPoint);
在C#中你可以这样定义
[StructLayout(LayoutKind.Sequential)]
public struct POINTAPI {//对应C中LPPOINT的定义
public int x;
public int y;
}
[DllImport("user32.dll", EntryPoint="GetCursorPos")]
public static extern bool GetCursorPos (ref POINTAPI lpPoint);//ref 就相当于指针