可以把c++的dll库的头文件自动转换为C#语言。
安装完成后打开,找到最后一个选项卡,在Native Code Snippet 中输入c代码,检查下面有没有错误,没有的话,点击Generate按钮,在右侧会自动生成c#代码。
最后把生成c#代码的“”替换成要用到的dll库文件名即可,如替换成“OVPS.dll”。
如输入c代码:
#ifdef OVPSIVD_API_API_EXPORTS
# define OVPSIVD_API extern "C" __declspec(dllexport)
#else
# define OVPSIVD_API extern "C" __declspec(dllimport)
#endif
#define OVPSIVD_CALL_METHOD __stdcall
OVPSIVD_API void OVPSIVD_CALL_METHOD OVPSIVD_Cleanup();
生成c#代码:
public partial class NativeConstants {
/// OVPSIVD_API -> extern "C" __declspec(dllimport)
/// Error generating expression: Expression is not parsable. Treating value as a raw string
public const string OVPSIVD_API = "extern \"C\" __declspec(dllimport)";
/// OVPSIVD_CALL_METHOD -> __stdcall
/// Error generating expression: Value __stdcall is not resolved
public const string OVPSIVD_CALL_METHOD = "__stdcall";
}
public partial class NativeMethods {
/// Return Type: void
[System.Runtime.InteropServices.DllImportAttribute("", EntryPoint="OVPSIVD_Cleanup", CallingConvention=System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern void OVPSIVD_Cleanup() ;
}
1