Win32Dll:
#define DLLEP __declspec(dllexport)
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern "C" DLLEP void Msg(void)
{
MessageBox(NULL,"void(*)(void)"," ",MB_OK);
}
如果要使用mfc类
extern "C" __declspec(dllexport) int DoModalDlg1()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
Dlg1 dlg1;
return dlg1.DoModal();
}
作为mfc扩展的dll
class AFX_EXT_CLASS CTipDlg : public CDialog
隐式调用
需考*.dll,*.lib,导入方式如下:
#pragma comment(lib,"Ex5_Win32dll.lib")
__declspec(dllimport) int Add(int x,int y);
__declspec(dllimport) void Msg(void);
显式调用
HINSTANCE hDLL; // Handle to DLL
hDLL = LoadLibrary("Ex_6MFCdll.dll");
if (hDLL != NULL)
{
int (*fun)();
fun = (int(*)())GetProcAddress(hDLL,"DoModalDlg1");
if (!fun)
{
MessageBox("not load fun");
// handle the error
return ;
}
else
{
// call the function
if(fun() == 1)
{
AfxMessageBox("ok");
}
else
{
AfxMessageBox("cancel");
}
}
FreeLibrary(hDLL);
}
else
{
AfxMessageBox("no load dll");
}
扩展类调用
1)
#include "TipDlg.h"
#pragma comment( lib, "Ex5_MFCExDll.lib" )
2)改dll的rescorse.h名include进来或者去掉emun={IDD=.....}