用VC 的 AppWizard生成了一个mfcappwizard(dll),想连入vc的程序中去。 一、用AppWizard生成了一个dll,(是MFC Appwizard(dll)),命名为MyDll 1、在MyDll.cpp中添加函数://系统是把他作为全局的函数好像 void DllTest(void) { AfxMessageBox("this is a dll function"); } 2、在MyDll.def中添加 DllTest @1二、建立基于对话框的一个应用程序UseDll,添加一个按钮, 1、在UserDllDlg.cpp中定义变量如下: HINSTANCE dll_handle=NULL; typedef void (*DLLTEST)(void); DLLTEST DllTest;//这两个变量是作为全局变量定义在类的外部 2、在OnButton()中添加代码:想显示链接dll并调用DllTest()函数,添加的代码如下: 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);
HINSTANCE ghDLL=NULL;
ghDLL = LoadLibrary("*.dll")GetProcAddress(ghDLL, "dll 中的函数名")FreeLibrary(ghDLL)
if (hinstDlltest)!= NULL
{
/*
Do something here....
*/
}
else
{
....
}
1。 LoadLibrary("*.dll")
2。GetProcAddress();
3。FreeLibrary()。
一、用AppWizard生成了一个dll,(是MFC Appwizard(dll)),命名为MyDll
1、在MyDll.cpp中添加函数://系统是把他作为全局的函数好像
void DllTest(void)
{
AfxMessageBox("this is a dll function");
} 2、在MyDll.def中添加
DllTest @1二、建立基于对话框的一个应用程序UseDll,添加一个按钮, 1、在UserDllDlg.cpp中定义变量如下: HINSTANCE dll_handle=NULL;
typedef void (*DLLTEST)(void);
DLLTEST DllTest;//这两个变量是作为全局变量定义在类的外部 2、在OnButton()中添加代码:想显示链接dll并调用DllTest()函数,添加的代码如下: 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);