help:怎样可以实现DLL中调用EXE中的函数

yuehuazheng 2002-11-25 09:06:44
我写了一个程序,在主程序中调用了动态链接库,传递了一些参数到动态链接库中,现在我又准备在动态链接库中调用主程序中的某个函数,但就是不知道怎么样实现,哪位大侠知道,谢谢
...全文
32 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuehuazheng 2002-11-25
  • 打赏
  • 举报
回复
我也想通过GetProcessAddress在DLL中调用EXE中的函数,但不知在应用程序中定义输出函数和在DLL中定义输出汉数有何区别以及如何在DLL中获得EXE的句柄?谢谢!
yonghengdizhen 2002-11-25
  • 打赏
  • 举报
回复
动态链接苦调用主程序中的函数你同样可以通过GetProcessAddress去调用..
如果是希望静态装入,你可为EXE产生导出库,然后在dll的Project中将其连入..
不过并不建议这么做.会降低程序的模块化程度.违背了设计动态连接库的初衷..

yonghengdizhen 2002-11-25
  • 打赏
  • 举报
回复
GetModuleHandle
The GetModuleHandle function retrieves a module handle for the specified module if the file has been mapped into the address space of the calling process.

To avoid the race conditions described in the Remarks section, use the GetModuleHandleEx function.

HMODULE GetModuleHandle(
LPCTSTR lpModuleName // module name
);
Parameters
lpModuleName
[in] Pointer to a null-terminated string that contains the name of the module (either a .dll or .exe file). If the file name extension is omitted, the default library extension .dll is appended. The file name string can include a trailing point character (.) to indicate that the module name has no extension. The string does not have to specify a path. When specifying a path, be sure to use backslashes (\), not forward slashes (/). The name is compared (case independently) to the names of modules currently mapped into the address space of the calling process.
If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process.

Return Values
If the function succeeds, the return value is a handle to the specified module.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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