利用GetModuleFileName得到当前程序运行路径;
原型:
1 WINBASEAPI
2 DWORD
3 WINAPI
4 GetModuleFileNameW(
5 __in_opt HMODULE hModule,
6 __out_ecount_part(nSize, return + 1 ) LPWCH lpFilename,
7 __in DWORD nSize
8 );
头文件:WinBase.h
实例:
1 WCHAR path[MAX_PATH];
2 char chpath[MAX_PATH];
3
4 GetModuleFileName(NULL,path, sizeof (path));
5
6 wcstombs(chpath,path,MAX_PATH);
7 std::cout << chpath << std::endl;