Utils: Win32: Fix API usage

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2021-04-02 09:06:32 +08:00
parent 95d72997ed
commit 97d9009500
1 changed files with 2 additions and 2 deletions

View File

@ -563,10 +563,10 @@ QImage Utilities::getDesktopWallpaperImage(const int screen)
qWarning() << "Failed to initialize COM."; qWarning() << "Failed to initialize COM.";
} }
qDebug() << "Shell API failed. Using SystemParametersInfoW instead."; qDebug() << "Shell API failed. Using SystemParametersInfoW instead.";
LPWSTR wallpaperPath = nullptr; const auto wallpaperPath = new WCHAR[MAX_PATH];
if (SystemParametersInfoW(SPI_GETDESKWALLPAPER, MAX_PATH, wallpaperPath, 0) != FALSE) { if (SystemParametersInfoW(SPI_GETDESKWALLPAPER, MAX_PATH, wallpaperPath, 0) != FALSE) {
const QString _path = QString::fromWCharArray(wallpaperPath); const QString _path = QString::fromWCharArray(wallpaperPath);
CoTaskMemFree(wallpaperPath); delete [] wallpaperPath;
return QImage(_path); return QImage(_path);
} }
qWarning() << "SystemParametersInfoW failed. Reading from the registry instead."; qWarning() << "SystemParametersInfoW failed. Reading from the registry instead.";