1
0
Fork 0

DBG: full unicode support in ResolveShortcut

This commit is contained in:
Duncan Ogilvie 2017-09-30 14:30:40 +02:00
parent 1143621eb1
commit ba6e6dea63
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
3 changed files with 17 additions and 11 deletions

View File

@ -324,7 +324,8 @@ bool IsWow64()
}
//Taken from: http://www.cplusplus.com/forum/windows/64088/
bool ResolveShortcut(HWND hwnd, const wchar_t* szShortcutPath, char* szResolvedPath, size_t nSize)
//And: https://codereview.stackexchange.com/a/2917
bool ResolveShortcut(HWND hwnd, const wchar_t* szShortcutPath, wchar_t* szResolvedPath, size_t nSize)
{
if(szResolvedPath == NULL)
return SUCCEEDED(E_INVALIDARG);
@ -334,8 +335,8 @@ bool ResolveShortcut(HWND hwnd, const wchar_t* szShortcutPath, char* szResolvedP
return false;
//Get a pointer to the IShellLink interface.
IShellLink* psl = NULL;
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
IShellLinkW* psl = NULL;
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID*)&psl);
if(SUCCEEDED(hres))
{
//Get a pointer to the IPersistFile interface.
@ -354,12 +355,16 @@ bool ResolveShortcut(HWND hwnd, const wchar_t* szShortcutPath, char* szResolvedP
if(SUCCEEDED(hres))
{
//Get the path to the link target.
char szGotPath[MAX_PATH] = {0};
hres = psl->GetPath(szGotPath, _countof(szGotPath), NULL, SLGP_SHORTPATH);
wchar_t linkTarget[MAX_PATH];
hres = psl->GetPath(linkTarget, _countof(linkTarget), NULL, SLGP_RAWPATH);
if(SUCCEEDED(hres))
//Expand the environment variables.
wchar_t expandedTarget[MAX_PATH];
auto expandSuccess = !!ExpandEnvironmentStringsW(linkTarget, expandedTarget, _countof(expandedTarget));
if(SUCCEEDED(hres) && expandSuccess)
{
strcpy_s(szResolvedPath, nSize, szGotPath);
wcscpy_s(szResolvedPath, nSize, expandedTarget);
}
}
}

View File

@ -64,7 +64,7 @@ bool GetFileNameFromProcessHandle(HANDLE hProcess, char* szFileName);
bool GetFileNameFromModuleHandle(HANDLE hProcess, HMODULE hModule, char* szFileName);
bool settingboolget(const char* section, const char* name);
bool IsWow64();
bool ResolveShortcut(HWND hwnd, const wchar_t* szShortcutPath, char* szResolvedPath, size_t nSize);
bool ResolveShortcut(HWND hwnd, const wchar_t* szShortcutPath, wchar_t* szResolvedPath, size_t nSize);
void WaitForThreadTermination(HANDLE hThread, DWORD timeout = INFINITE);
void WaitForMultipleThreadsTermination(const HANDLE* hThread, int count, DWORD timeout = INFINITE);

View File

@ -56,11 +56,12 @@ bool cbDebugInit(int argc, char* argv[])
if(IsArgumentsLessThan(argc, 2))
return false;
strcpy_s(arg1, argv[1]);
char szResolvedPath[MAX_PATH] = "";
wchar_t szResolvedPath[MAX_PATH] = L"";
if(ResolveShortcut(GuiGetWindowHandle(), StringUtils::Utf8ToUtf16(arg1).c_str(), szResolvedPath, _countof(szResolvedPath)))
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Resolved shortcut \"%s\"->\"%s\"\n"), arg1, szResolvedPath);
strcpy_s(arg1, szResolvedPath);
auto resolvedPathUtf8 = StringUtils::Utf16ToUtf8(szResolvedPath);
dprintf(QT_TRANSLATE_NOOP("DBG", "Resolved shortcut \"%s\"->\"%s\"\n"), arg1, resolvedPathUtf8.c_str());
strcpy_s(arg1, resolvedPathUtf8.c_str());
}
if(!FileExists(arg1))
{