在运行时获取DLL路径 [英] Get DLL path at runtime

查看:344
本文介绍了在运行时获取DLL路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在其代码中获取 dll的目录(或文件)路径。 (不是程序的.exe文件路径)

I want to get a dll's directory (or file) path from within its code. (not the program's .exe file path)

我已经尝试了一些我找到的方法:

GetCurrentDir - 获取当前目录路径。

GetModuleFileName - 获取可执行文件的路径。

I've tried a few methods I've found:
GetCurrentDir - gets the current directory path.
GetModuleFileName - gets the executable's path.

那么我如何知道代码在哪个dll中呢?

我正在寻找类似于C#的的东西Assembly.GetExecutingAssembly

So how can i find out in which dll the code is in ?
I'm looking for something similar to C#'s Assembly.GetExecutingAssembly

推荐答案

EXTERN_C IMAGE_DOS_HEADER __ImageBase;

....

WCHAR   DllPath[MAX_PATH] = {0};
GetModuleFileNameW((HINSTANCE)&__ImageBase, DllPath, _countof(DllPath));

这篇关于在运行时获取DLL路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆