`
paulfzm
  • 浏览: 873041 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

MFC 调用dll

    博客分类:
  • vc++
MFC 
阅读更多

 

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);  
} 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics