1.c++的导出函数通过def文件说明
bool CreateFormEditor(HWND hWndParent) //不用头文件说明
{
RECT rcRect = {0, 0, 400, 300};
if( !g_FormEdit.Create(hWndParent, &rcRect, WS_CHILD | WS_VISIBLE) )
return false;
return true;
}
def文件
EXPORTS
CreateFormEditor
2.使用__declspec(dllexport)
工程要定义FORMEDITOR_EXT 这个宏
#ifdef FORMEDITOR_EXT
#define XFORMEDITOR_EXT __declspec(dllexport)
#else
#define XFORMEDITOR_EXT __declspec(dllimport)
#endif
头文件
XFORMEDITOR_EXT HINSTANCE WINAPI GetFormEditorInstance();
cpp文件
XFORMEDITOR_EXT HINSTANCE WINAPI GetFormEditorInstance()
{
return m_hInstance;
}
c#调用
[DllImport(@"FormEditor.dll", EntryPoint = "CreateFormEditor")]
public static extern bool CreateFormEditor(IntPtr hParentWnd);
如果不用def文件,导出函数要加extern c否则函数名称会改变,具体可以用dependency工具查看。
bool CreateFormEditor(HWND hWndParent) //不用头文件说明
{
RECT rcRect = {0, 0, 400, 300};
if( !g_FormEdit.Create(hWndParent, &rcRect, WS_CHILD | WS_VISIBLE) )
return false;
return true;
}
def文件
EXPORTS
CreateFormEditor
2.使用__declspec(dllexport)
工程要定义FORMEDITOR_EXT 这个宏
#ifdef FORMEDITOR_EXT
#define XFORMEDITOR_EXT __declspec(dllexport)
#else
#define XFORMEDITOR_EXT __declspec(dllimport)
#endif
头文件
XFORMEDITOR_EXT HINSTANCE WINAPI GetFormEditorInstance();
cpp文件
XFORMEDITOR_EXT HINSTANCE WINAPI GetFormEditorInstance()
{
return m_hInstance;
}
c#调用
[DllImport(@"FormEditor.dll", EntryPoint = "CreateFormEditor")]
public static extern bool CreateFormEditor(IntPtr hParentWnd);
如果不用def文件,导出函数要加extern c否则函数名称会改变,具体可以用dependency工具查看。