前言:

比如 我们有个 test.exe 加载了 A.dll 然后 A.dll 内部又加载了 B.dll
test.exe 比如在 c盘 A.dll 在D盘 B.dll在E盘

那么 我在B.dll 怎么获取到 加载我的模块的路径呢?

GetModuleFileName 这个第一个参数如果填NULL
获取到的肯定是 test.exe 的路径 也就是进程的启动路径 c盘

c++ 在dll 中获取 dll 的路径 reinterpret_cast<HINSTANCE>(&IMAGE_DOS_HEADER)

我们要获取到加载我们的dll 路径要这样获取
c++ 在dll 中获取 dll 的路径 reinterpret_cast<HINSTANCE>(&IMAGE_DOS_HEADER)
c++ 在dll 中获取 dll 的路径 reinterpret_cast<HINSTANCE>(&IMAGE_DOS_HEADER)

在B.dll 加入以上代码 调用 GetProgramDir() 函数返回的就是 A.dll 的路径了

c++ 在dll 中获取 dll 的路径 reinterpret_cast<HINSTANCE>(&IMAGE_DOS_HEADER)

我认为这个结构体有个字段是指向PE入口地址的 也就是A.dll 的地址吧

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-10-03
  • 2022-02-13
  • 2022-01-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
相关资源
相似解决方案