提交 35091d86 编写于 作者: GamebabyRockSun_QQ's avatar GamebabyRockSun_QQ

更新了查找App路径的处理,换做直接取Exe文件路径,然后剔除多余部分的方法,这样不论是在IDE中调试启动,还是在Debug路径中启动,APP总是能找到正确的路径

上级 549a5e9d
......@@ -269,15 +269,26 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR l
{
// 得到当前的工作目录,方便我们使用相对路径来访问各种资源文件
{
UINT nBytes = GetCurrentDirectory(MAX_PATH, g_pszAppPath);
if (MAX_PATH == nBytes)
if (0 == ::GetModuleFileName(nullptr, g_pszAppPath, MAX_PATH))
{
GRS_THROW_IF_FAILED(HRESULT_FROM_WIN32(GetLastError()));
}
WCHAR* lastSlash = _tcsrchr(g_pszAppPath, _T('\\'));
if (lastSlash)
{
{//删除Exe文件名
*(lastSlash) = _T('\0');
}
lastSlash = _tcsrchr(g_pszAppPath, _T('\\'));
if (lastSlash)
{//删除x64路径
*(lastSlash) = _T('\0');
}
lastSlash = _tcsrchr(g_pszAppPath, _T('\\'));
if (lastSlash)
{//删除Debug 或 Release路径
*(lastSlash + 1) = _T('\0');
}
}
......
......@@ -358,15 +358,26 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR l
// 得到当前的工作目录,方便我们使用相对路径来访问各种资源文件
{
UINT nBytes = GetCurrentDirectory(MAX_PATH, g_pszAppPath);
if (MAX_PATH == nBytes)
if (0 == ::GetModuleFileName(nullptr, g_pszAppPath, MAX_PATH))
{
GRS_THROW_IF_FAILED(HRESULT_FROM_WIN32(GetLastError()));
}
WCHAR* lastSlash = _tcsrchr(g_pszAppPath, _T('\\'));
if (lastSlash)
{
{//删除Exe文件名
*(lastSlash) = _T('\0');
}
lastSlash = _tcsrchr(g_pszAppPath, _T('\\'));
if (lastSlash)
{//删除x64路径
*(lastSlash) = _T('\0');
}
lastSlash = _tcsrchr(g_pszAppPath, _T('\\'));
if (lastSlash)
{//删除Debug 或 Release路径
*(lastSlash + 1) = _T('\0');
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册