Get path of executable

前端 未结 23 1936
清歌不尽
清歌不尽 2020-11-22 07:04

I know this question has been asked before but I still haven\'t seen a satisfactory answer, or a definitive \"no, this cannot be done\", so I\'ll ask again!

All I wa

23条回答
  •  梦如初夏
    2020-11-22 07:42

    In case you need to handle unicode paths for Windows:

    #include 
    #include 
    
    int wmain(int argc, wchar_t * argv[])
    {
        HMODULE this_process_handle = GetModuleHandle(NULL);
        wchar_t this_process_path[MAX_PATH];
    
        GetModuleFileNameW(NULL, this_process_path, sizeof(this_process_path));
    
        std::wcout << "Unicode path of this app: " << this_process_path << std::endl;
    
        return 0;
    }
    

提交回复
热议问题