include <windows.h>
bool GetSelfModulePath(char* path)
{
MEMORY_BASIC_INFORMATION mbi;
HMODULE dllHandle = ((::VirtualQuery(GetSelfModulePath, &mbi, sizeof(mbi)) != 0) ? (HMODULE)mbi.AllocationBase : NULL);
TCHAR t_path[MAX_PATH] = { 0 };
GetModuleFileName(dllHandle, t_path, MAX_PATH);
int iLength = WideCharToMultiByte(CP_ACP, 0, t_path, -1, NULL, 0, NULL, NULL);
return WideCharToMultiByte(CP_ACP, 0, t_path, -1, path, iLength, NULL, NULL);
}
Ps: 拿到path之后,应尽量去掉可能的尾部空数据