Skip to content

Commit

Permalink
[GUI] Use wchar_t API explicitly on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzzbawls committed Jan 30, 2021
1 parent 6143f80 commit 607f340
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
26 changes: 13 additions & 13 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,36 +648,36 @@ bool SetStartOnSystemStartup(bool fAutoStart)
CoInitialize(NULL);

// Get a pointer to the IShellLink interface.
IShellLink* psl = NULL;
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink,
IShellLinkW* psl = nullptr;
HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr,
CLSCTX_INPROC_SERVER, IID_IShellLinkW,
reinterpret_cast<void**>(&psl));

if (SUCCEEDED(hres)) {
// Get the current executable path
TCHAR pszExePath[MAX_PATH];
GetModuleFileName(NULL, pszExePath, sizeof(pszExePath));
WCHAR pszExePath[MAX_PATH];
GetModuleFileNameW(nullptr, pszExePath, ARRAYSIZE(pszExePath));

TCHAR pszArgs[5] = TEXT("-min");
// Start client minimized
QString strArgs = "-min";
// Set -testnet /-regtest options
strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false)));

// Set the path to the shortcut target
psl->SetPath(pszExePath);
PathRemoveFileSpec(pszExePath);
PathRemoveFileSpecW(pszExePath);
psl->SetWorkingDirectory(pszExePath);
psl->SetShowCmd(SW_SHOWMINNOACTIVE);
psl->SetArguments(pszArgs);
psl->SetArguments(strArgs.toStdWString().c_str());

// Query IShellLink for the IPersistFile interface for
// saving the shortcut in persistent storage.
IPersistFile* ppf = NULL;
IPersistFile* ppf = nullptr;
hres = psl->QueryInterface(IID_IPersistFile,
reinterpret_cast<void**>(&ppf));
if (SUCCEEDED(hres)) {
WCHAR pwsz[MAX_PATH];
// Ensure that the string is ANSI.
MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().string().c_str(), -1, pwsz, MAX_PATH);
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(pwsz, TRUE);
hres = ppf->Save(StartupShortcutPath().wstring().c_str(), TRUE);
ppf->Release();
psl->Release();
CoUninitialize();
Expand Down
6 changes: 3 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,13 +737,13 @@ void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length)
#ifdef WIN32
fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
{
char pszPath[MAX_PATH] = "";
WCHAR pszPath[MAX_PATH] = L"";

if (SHGetSpecialFolderPathA(NULL, pszPath, nFolder, fCreate)) {
if (SHGetSpecialFolderPathW(nullptr, pszPath, nFolder, fCreate)) {
return fs::path(pszPath);
}

LogPrintf("SHGetSpecialFolderPathA() failed, could not obtain requested path.\n");
LogPrintf("SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
return fs::path("");
}
#endif
Expand Down

0 comments on commit 607f340

Please sign in to comment.