【发布时间】:2012-01-26 04:46:32
【问题描述】:
假设我有一个名为 MyDll.dll
的 dll它在 d:\MyWorks\MyDll.dll [它是 directshow dll]
我想从 MyDll 代码中获取其位置的路径。
我为此使用了 boost: 文件系统
string path = "";
boost::filesystem::path full_path( boost::filesystem::current_path() );
path = full_path.string();
但这给了我它的执行路径,它是 C:\Windows\system32,而不是它的位置路径是 d:\MyWorks\MyDll.dll。
如何在同一个 dll 中获取 dll 的位置?
更新:通过获取模块:
TCHAR path[2048];
GetModuleFileName( NULL, path, 2048 );
ostringstream file;
file << path ;
string const pathString =file.str();
cout << "Path: " << pathString << endl;
只给我类似十六进制的字符串:0049EA95....
【问题讨论】:
-
请看GetModuleFileName:msdn.microsoft.com/en-us/library/windows/desktop/…
-
我尝试 GetModuleFileName 得到一些奇怪的文本...无法正确地将其分配给字符串可能是 @Lucian
标签: c++ windows visual-c++ dll boost