#ifdef Q_WS_WIN
#include "qt_windows.h"
#include "qlibrary.h"
#ifndef CSIDL_COMMON_APPDATA
#define CSIDL_COMMON_APPDATA 0x0023 // All Users\Application Data
#endif
#ifndef CSIDL_APPDATA
#define CSIDL_APPDATA 0x001a // <username>\Application Data
#endif
QString MyClass
::specialFolder(int type
) {
QT_WA( {
typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPTSTR, int, BOOL);
GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW");
if (SHGetSpecialFolderPath) {
TCHAR path[MAX_PATH];
SHGetSpecialFolderPath(0, path, type, FALSE);
result
= QString::fromUtf16((ushort
*)path
);
}
} , {
typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, char*, int, BOOL);
GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathA");
if (SHGetSpecialFolderPath) {
char path[MAX_PATH];
SHGetSpecialFolderPath(0, path, type, FALSE);
result
= QString::fromLocal8Bit(path
);
}
} );
// Fallback on error
if (result.isEmpty()) {
switch (type) {
case CSIDL_COMMON_APPDATA:
break;
case CSIDL_APPDATA:
break;
default:
;
}
}
return result;
}
#ifdef Q_WS_WIN
#include "qt_windows.h"
#include "qlibrary.h"
#ifndef CSIDL_COMMON_APPDATA
#define CSIDL_COMMON_APPDATA 0x0023 // All Users\Application Data
#endif
#ifndef CSIDL_APPDATA
#define CSIDL_APPDATA 0x001a // <username>\Application Data
#endif
QString MyClass::specialFolder(int type)
{
QString result;
QLibrary library(QLatin1String("shell32"));
QT_WA( {
typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPTSTR, int, BOOL);
GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW");
if (SHGetSpecialFolderPath) {
TCHAR path[MAX_PATH];
SHGetSpecialFolderPath(0, path, type, FALSE);
result = QString::fromUtf16((ushort*)path);
}
} , {
typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, char*, int, BOOL);
GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathA");
if (SHGetSpecialFolderPath) {
char path[MAX_PATH];
SHGetSpecialFolderPath(0, path, type, FALSE);
result = QString::fromLocal8Bit(path);
}
} );
// Fallback on error
if (result.isEmpty()) {
switch (type) {
case CSIDL_COMMON_APPDATA:
result = QLatin1String("C:\\temp\\qt-common");
break;
case CSIDL_APPDATA:
result = QLatin1String("C:\\temp\\qt-user");
break;
default:
;
}
}
return result;
}
To copy to clipboard, switch view to plain text mode
Bookmarks