C++ C++;使用Boost获取modulefilename
我有以下代码需要从windows移植到boost:C++ C++;使用Boost获取modulefilename,c++,boost,C++,Boost,我有以下代码需要从windows移植到boost: BOOL Class::fn_GetModulePath(WCHAR szPath[MAX_PATH]) { BOOL bReturn = FALSE; dll::library_handle hDll = dll::load_shared_library((const char*)DC_DLL_FILENAME); //HMODULE hDll = LoadLibrary(DC_DLL_FILENAME);
BOOL Class::fn_GetModulePath(WCHAR szPath[MAX_PATH])
{
BOOL bReturn = FALSE;
dll::library_handle hDll = dll::load_shared_library((const char*)DC_DLL_FILENAME);
//HMODULE hDll = LoadLibrary(DC_DLL_FILENAME);
if (hDll)
{
// This function needs replacing
DWORD dwResult = GetModuleFileName(hDll,szPath,MAX_PATH);
dll::close_shared_library(hDll);
//FreeLibrary(hDll);
if (dwResult)
{
int iLen = (int) wcslen(szPath);
if (iLen)
{
for (int i = iLen; i >= 0; i--)
{
if(szPath[i] == '\\')
{
szPath[i+1] = 0;
break;
}
}
}
bReturn = TRUE;
}
}
return bReturn;
}
如何使用Boost实现GetModuleFileName
函数
感谢您的帮助 您可以这样使用:
如果您试图获取当前正在运行的代码的路径,即
boost::dll::this_line_location()
boost::dll::shared_library
类有一个方法location
,该方法返回库的完整路径
对于整个程序,有boost::dll::program\u location
global函数
此外,可以通过符号地址和源位置找到可执行文件或库位置:
boost::dll::symbol_location
boost::dll::this_line_location
后者只能由模块用于查找自己的位置。这是否回答了您的问题@不,遗憾的是它没有。这个dll::library\u句柄类型在哪里/如何定义?名称空间dll=boost::extensions::impl;然后是boost的库句柄类型在我的boost副本中没有
库句柄
标识符。
boost::dll::symbol_location
boost::dll::this_line_location