c++ - C++ GetModuleFileName 使用 Boost
问题描述
我有以下代码需要从 Windows 移植来提升:
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;
}
我将如何GetModuleFileName
使用 Boost 来实现该功能?
任何帮助表示赞赏!
解决方案
boost::dll::shared_library
类有一个location
返回库的完整路径的方法。
对于整个程序,有boost::dll::program_location
全局功能。
此外,可以通过符号地址和源位置找到可执行文件或库位置:
boost::dll::symbol_location
boost::dll::this_line_location
后者只能被模块用来查找自己的位置。
推荐阅读
- forms - 当 API 源生成表单控制选项时,浮动标签不起作用
- pandas - 使用新 pyspark.pandas 的正确方法?
- python - 如何使用python从交易视图中的指标获取价值
- python - Elasticsearch - 计算索引中所有文本中的单词出现次数
- sql - SNOWFLAKE 数据库中关于主键错误的合并语句
- python - Bandit B404 子流程导入的安全问题?
- python - 如何在numpy中矩阵乘以3个矩阵?
- android - 如何转到另一个选项卡,但保留上一个选项卡
- javascript - 为什么 Javascript 的 FileReader 它不维护 .csv 扩展名
- image-segmentation - 使用傅里叶变换或霍夫变换确定二值图像线的对齐方式?