GetModuleFileName
現在のプロセスでロードされたモジュールのファイルのフルパスを取得します。モジュールは現在のプロセスによってロードされる必要があります。
ヘッダーファイルはwindows.h
です。
#include <windows.>
std::string GetAppPath()
{
char buffer[512] = {
0};
GetModuleFileName(nullptr, buffer, sizeof(512));
std::string appPath = buffer;
appPath = appPath.substr(0, appPath, rfind("\\"));
return appPath;
}
戻りパス値で使用される区切り文字は\\であることに注意してください(例:D:\\ Test \\ Result \\ Test.exe)。