31 #include <QtCore/QString>
32 #include <QtCore/QVector>
33 #include <QtCore/QDebug>
34 #include <QtCore/QLibrary>
35 #include <QtCore/QTextStream>
41 QString rc = QString::fromLatin1(
"#%1: ").arg(error);
44 const int len = FormatMessage(
45 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
46 NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
48 rc = QString::fromUtf16(lpMsgBuf, len);
51 rc += QString::fromLatin1(
"<unknown error>");
58 QString *errorMessage)
61 typedef DWORD (APIENTRY *GetFileVersionInfoSizeProtoType)(LPCTSTR, LPDWORD);
62 typedef BOOL (APIENTRY *GetFileVersionInfoWProtoType)(LPCWSTR, DWORD, DWORD, LPVOID);
63 typedef BOOL (APIENTRY *VerQueryValueWProtoType)(
const LPVOID, LPWSTR lpSubBlock, LPVOID, PUINT);
65 const char *versionDLLC =
"version.dll";
66 QLibrary versionLib(QLatin1String(versionDLLC), 0);
67 if (!versionLib.load()) {
68 *errorMessage = QString::fromLatin1(
"Unable load %1: %2").arg(QLatin1String(versionDLLC), versionLib.errorString());
72 GetFileVersionInfoSizeProtoType getFileVersionInfoSizeW = (GetFileVersionInfoSizeProtoType)(versionLib.resolve(
"GetFileVersionInfoSizeW"));
73 GetFileVersionInfoWProtoType getFileVersionInfoW = (GetFileVersionInfoWProtoType)(versionLib.resolve(
"GetFileVersionInfoW"));
74 VerQueryValueWProtoType verQueryValueW = (VerQueryValueWProtoType)(versionLib.resolve(
"VerQueryValueW"));
75 if (!getFileVersionInfoSizeW || !getFileVersionInfoW || !verQueryValueW) {
76 *errorMessage = QString::fromLatin1(
"Unable to resolve all required symbols in %1").arg(QLatin1String(versionDLLC));
82 const LPCTSTR fileName =
reinterpret_cast<LPCTSTR
>(name.utf16());
83 const DWORD infoSize = (*getFileVersionInfoSizeW)(fileName, &dummy);
85 *errorMessage = QString::fromLatin1(
"Unable to determine the size of the version information of %1: %2").arg(name,
winErrorMessage(GetLastError()));
88 QByteArray dataV(infoSize + 1,
'\0');
89 char *
data = dataV.data();
90 if (!(*getFileVersionInfoW)(fileName, dummy, infoSize, data)) {
91 *errorMessage = QString::fromLatin1(
"Unable to determine the version information of %1: %2").arg(name,
winErrorMessage(GetLastError()));
94 VS_FIXEDFILEINFO *versionInfo;
96 WCHAR tmp1[] = TEXT(
"\\");
98 if (!(*verQueryValueW)(data, tmp, &versionInfo, &len)) {
99 *errorMessage = QString::fromLatin1(
"Unable to determine version string of %1: %2").arg(name,
winErrorMessage(GetLastError()));
105 QTextStream(&rc) << HIWORD(versionInfo->dwFileVersionMS) <<
'.' << LOWORD(versionInfo->dwFileVersionMS);
108 QTextStream(&rc) << HIWORD(versionInfo->dwProductVersionMS) <<
'.' << LOWORD(versionInfo->dwProductVersionMS);
QTCREATOR_UTILS_EXPORT QString winErrorMessage(unsigned long error)
QTCREATOR_UTILS_EXPORT QString winGetDLLVersion(WinDLLVersionType t, const QString &name, QString *errorMessage)
else error('Your technical computing program does not support file choosers.Please input the file name in the argument. ') end elseif nargin >0 logfile