Skip to content

Commit 3625187

Browse files
committed
Merge #13734: gui: Drop boost::scoped_array and use wchar_t API explicitly on Windows
bb6ca65 gui: get special folder in unicode (Chun Kuan Lee) 1c5d225 Drop boost::scoped_array (Chun Kuan Lee) Pull request description: Drop boost::scoped_array and simplify the code. `TCHAR` should be defined as `wchar_t` if `UNICODE` is defined. So we can use `.toStdWString().c_str()` to get wchar_t C-style string. Fix #13819 Tree-SHA512: 3fd4aa784129c9d1576b01e6ee27faa42d793e152d132f2dde504d917dad3a8e95e065fcbc54a3895d74fb6b2a9ed4f5ec67d893395552f585e225486a84a454
2 parents 0de0abc + bb6ca65 commit 3625187

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

src/qt/guiutil.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
#include <shlwapi.h>
3939
#endif
4040

41-
#include <boost/scoped_array.hpp>
42-
4341
#include <QAbstractItemView>
4442
#include <QApplication>
4543
#include <QClipboard>
@@ -548,52 +546,37 @@ bool SetStartOnSystemStartup(bool fAutoStart)
548546
CoInitialize(nullptr);
549547

550548
// Get a pointer to the IShellLink interface.
551-
IShellLink* psl = nullptr;
549+
IShellLinkW* psl = nullptr;
552550
HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr,
553-
CLSCTX_INPROC_SERVER, IID_IShellLink,
551+
CLSCTX_INPROC_SERVER, IID_IShellLinkW,
554552
reinterpret_cast<void**>(&psl));
555553

556554
if (SUCCEEDED(hres))
557555
{
558556
// Get the current executable path
559-
TCHAR pszExePath[MAX_PATH];
560-
GetModuleFileName(nullptr, pszExePath, sizeof(pszExePath));
557+
WCHAR pszExePath[MAX_PATH];
558+
GetModuleFileNameW(nullptr, pszExePath, ARRAYSIZE(pszExePath));
561559

562560
// Start client minimized
563561
QString strArgs = "-min";
564562
// Set -testnet /-regtest options
565563
strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false)));
566564

567-
#ifdef UNICODE
568-
boost::scoped_array<TCHAR> args(new TCHAR[strArgs.length() + 1]);
569-
// Convert the QString to TCHAR*
570-
strArgs.toWCharArray(args.get());
571-
// Add missing '\0'-termination to string
572-
args[strArgs.length()] = '\0';
573-
#endif
574-
575565
// Set the path to the shortcut target
576566
psl->SetPath(pszExePath);
577-
PathRemoveFileSpec(pszExePath);
567+
PathRemoveFileSpecW(pszExePath);
578568
psl->SetWorkingDirectory(pszExePath);
579569
psl->SetShowCmd(SW_SHOWMINNOACTIVE);
580-
#ifndef UNICODE
581-
psl->SetArguments(strArgs.toStdString().c_str());
582-
#else
583-
psl->SetArguments(args.get());
584-
#endif
570+
psl->SetArguments(strArgs.toStdWString().c_str());
585571

586572
// Query IShellLink for the IPersistFile interface for
587573
// saving the shortcut in persistent storage.
588574
IPersistFile* ppf = nullptr;
589575
hres = psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&ppf));
590576
if (SUCCEEDED(hres))
591577
{
592-
WCHAR pwsz[MAX_PATH];
593-
// Ensure that the string is ANSI.
594-
MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().string().c_str(), -1, pwsz, MAX_PATH);
595578
// Save the link by calling IPersistFile::Save.
596-
hres = ppf->Save(pwsz, TRUE);
579+
hres = ppf->Save(StartupShortcutPath().wstring().c_str(), TRUE);
597580
ppf->Release();
598581
psl->Release();
599582
CoUninitialize();

src/util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,14 +1139,14 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
11391139
#ifdef WIN32
11401140
fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
11411141
{
1142-
char pszPath[MAX_PATH] = "";
1142+
WCHAR pszPath[MAX_PATH] = L"";
11431143

1144-
if(SHGetSpecialFolderPathA(nullptr, pszPath, nFolder, fCreate))
1144+
if(SHGetSpecialFolderPathW(nullptr, pszPath, nFolder, fCreate))
11451145
{
11461146
return fs::path(pszPath);
11471147
}
11481148

1149-
LogPrintf("SHGetSpecialFolderPathA() failed, could not obtain requested path.\n");
1149+
LogPrintf("SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
11501150
return fs::path("");
11511151
}
11521152
#endif

test/lint/lint-includes.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ EXPECTED_BOOST_INCLUDES=(
6363
boost/optional.hpp
6464
boost/preprocessor/cat.hpp
6565
boost/preprocessor/stringize.hpp
66-
boost/scoped_array.hpp
6766
boost/signals2/connection.hpp
6867
boost/signals2/last_value.hpp
6968
boost/signals2/signal.hpp

0 commit comments

Comments
 (0)