EXE call Dll里的函数,然后Dll里的函数callback EXE里的函数
/*EXE代码
作者:SysProgram
日期:2011年3月23日
*/
void Msg(TCHAR *str)
{
MessageBox(0,str,"Caption",0);
}
void CTestDlgDlg::OnOK()
{
// TODO: Add extra validation here
typedef void (*MY_FARPROC)(void (*MY_FARPROC)(TCHAR *str));
HMODULE hModule = LoadLibrary("C://TestDll//Debug//TestDll.dll");
MY_FARPROC FunAddress;
if (hModule == NULL)
{
MessageBox("load dll error");
return;
}
FunAddress = (MY_FARPROC)GetProcAddress(hModule,"TestMsg");
FunAddress(Msg); //将Msg的地址传入dll
}
//---------------------------------------------------------------------------------------------------------------------------
/*DLL代码
作者:SysProgram
日期:2011年3月23日
*/
#include <windows.h>
void TestMsg(void (*MY_FARPROC)(TCHAR *str))
{
MY_FARPROC("hehe"); //回调EXE里的函数
}
BOOL WINAPI DllMain(
HINSTANCE hinstDLL, // handle to the DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpvReserved // reserved
)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
//.........................
}
}
//----------------------------------------------------------------------------------------------
//导出函数
EXPORTS
TestMsg
本文介绍了一个简单的示例,展示了如何实现EXE文件调用DLL中的函数,并由DLL回调EXE中的函数。通过具体代码示例,解释了加载DLL、获取函数地址及传递函数指针的方法。
6735

被折叠的 条评论
为什么被折叠?



