请教:如何在不同进程之间传递CALLBACK函数指针?急!!!

leoleo 2002-01-20 07:49:22
如何在不同进程之间传递CALLBACK函数指针?
例如,
//callback function pointer declaration
typedef int (*ProcTest)();

APP_A.exe中实现
1.
//callback service routine
int DpsAddToGal()
{
//..
}
2.
//调用test.dll 的输出函数 exptest(ProcTest* ptest)传递函数指针;
exptest(DpsAddToGal);

那么test.dll 的输出函数 exptest()接收了函数指针,并启动APP-B.exe,
如何将该函数指针传递给APP-B进程,从而在APP-B.exe中执行APP_A.exe的某些功能?
...全文
134 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
mathe 2002-01-20
  • 打赏
  • 举报
回复
Different process may using different address for the same function. You should not using the fuction pointer of another function.
But you could use the relative address of the function.
in ProcA:
HANDLE hModule=GetModuleHandle("test.dll");
DWORD dwRelativeAddress=(DWORD)funpointer - (DWORD) hModule;
SendMessage(hWndOfAppB,WM_YOUR_MESSAGE,0,dwRelativeAddress);
in ProcB:
After receive the message, get relative address of function for lParam,then
HANDLE hModule=GetModuleHandle("test.dll");
funpointer=(FunType)((DWORD)hModule+lParam);
now you could call the function.

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧