MFC 调用dll

 

typedef void (*lpFun)(void);
 HINSTANCE hDll; //DLL句柄
 hDll = LoadLibrary(L"TestDll5.dll");
 if (NULL==hDll)
 {
  MessageBox(L"DLL加载失败");
 }
 lpFun addFun; //函数指针
 lpFun pShowDlg = (lpFun)GetProcAddress(hDll,"ShowDlg");
 if (NULL==pShowDlg)
 {
  MessageBox(L"DLL中函数寻找失败");
 }
 pShowDlg();

 

 

HINSTANCE hInst;
	hInst=LoadLibrary(L"Dll1.dll");
	typedef int (/*_stdcall*/ *AddProc)(int,int);
	AddProc Add = (AddProc)GetProcAddress(hInst,"add");
	if(!Add)
	{
		MessageBox(L"加载dll失败!");
		return;
	}
	CString str;
	str.Format(L"5+3=%d",Add(5,3));
	MessageBox(str);
	FreeLibrary(hInst);

 

 

对于调用Dll使用非模态创建窗口一闪而过的情况,可以使用消息循环来显示窗口

MSG msg; 
while (GetMessage(&msg, NULL, 0, 0)) 
{  
     TranslateMessage(&msg);  
     DispatchMessage(&msg);  
} 

 

你可能感兴趣的:(mfc)