用VC的MFC創(chuàng)建兩個(gè)DLL和一個(gè)EXE,,該如何在EXE中調(diào)用DLL中的函數(shù),?或者在一個(gè)DLL中調(diào)用另外一個(gè)DLL中的函數(shù)?
VC建立DLL并調(diào)用它的一個(gè)方法 DLL可以讓一個(gè)項(xiàng)目中不同編程語(yǔ)言共享代碼
用VC 的 AppWizard生成了一個(gè)mfcappwizard(dll),,想連入vc的程序中去,。
一、用AppWizard生成了一個(gè)dll,,(是MFC Appwizard(dll)),,命名為MyDll 1、在MyDll.cpp中添加函數(shù)://系統(tǒng)是把他作為全局的函數(shù)好像 void DllTest(void) { AfxMessageBox("this is a dll function"); }
2,、在MyDll.def中添加 DllTest @1
二,、建立基于對(duì)話框的一個(gè)應(yīng)用程序UseDll,添加一個(gè)按鈕,,
1,、在UserDllDlg.cpp中定義變量如下:
HINSTANCE dll_handle=NULL; typedef void (*DLLTEST)(void); DLLTEST DllTest;//這兩個(gè)變量是作為全局變量定義在類的外部
2,、在OnButton()中添加代碼:想顯示鏈接dll并調(diào)用DllTest()函數(shù),,添加的代碼如下:
Dll_handle=LoadLibrary("...\...\...\Mydll.dll");//dll文件的路徑 if(Dll_handle==NULL) { AfxMessageBox("dll has not be loaded !"); return; } DllTest=(DLLTEST)GetProcAddress(Dll_handle,"DllTest"); if(DllTest==NULL) { AfxMessageBox("dll function has not be loaded !"); return; } AfxMessageBox("begin to use function"); DllTest(); AfxMessageBox("end of use function"); FreeLibrary(Dll_handle);
|