NX二次開發-獲取當前dll的專案路徑、獲取配置檔案路徑
阿新 • • 發佈:2020-12-14
NX二次開發-獲取當前dll的專案路徑、獲取配置檔案路徑
- 獲取當前dll的專案路徑;
1 string NXCommon::GetUserDir() 2 { 3 std::string dll = GetHostName(); 4 string dir, fname; 5 SplitFileName(dll, dir, fname); 6 7 string mdlName = GetModuleFullPath(fname); 8 string tailName = "application\\" + fname; 9 10 stringuserDir = mdlName.substr(0, mdlName.size() - tailName.size()); 11 12 return userDir; 13 }
1 string GetHostName() 2 { 3 HMODULE handle = NULL; 4 5 bool isOK = GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, 6 (char*)_ReturnAddress(), &handle);7 8 if (isOK) 9 { 10 char name[1024] = { 0 }; 11 GetModuleFileNameA(handle, name, 1024); 12 13 return std::string(name); 14 } 15 else 16 { 17 return ""; 18 } 19 }
1 std::string GetModuleFullPath(std::stringdllName) 2 { 3 HMODULE handle = GetModuleHandleA(dllName.c_str()); 4 5 char lpFileName[_MAX_PATH + 1] = { '/0' }; 6 GetModuleFileNameA(handle, lpFileName, _MAX_PATH); 7 8 return std::string(lpFileName); 9 }
- 獲取配置檔案路徑。
1 string NXCommon::GetConfigDir() 2 { 3 return GetUserDir() + "config\\"; 4 }