39
* Fallback for vbglR3GetAdditionsVersion.
39
* Fallback for VbglR3GetAdditionsVersion.
41
41
static int vbglR3GetAdditionsCompileTimeVersion(char **ppszVer, char **ppszVerEx, char **ppszRev)
43
/* Raw version string: major.minor.build. */
43
int rc = VINF_SUCCESS;
46
*ppszVer = RTStrDup(VBOX_VERSION_STRING_RAW);
48
return VERR_NO_STR_MEMORY;
51
/* Extended version string: major.minor.build (+ vendor [suffix(es)]). */
54
*ppszVerEx = RTStrDup(VBOX_VERSION_STRING);
56
return VERR_NO_STR_MEMORY;
62
RTStrPrintf(szRev, sizeof(szRev), "%d", VBOX_SVN_REV);
63
*ppszRev = RTStrDup(szRev);
45
rc = RTStrDupEx(ppszVer, VBOX_VERSION_STRING_RAW);
49
rc = RTStrDupEx(ppszVerEx, VBOX_VERSION_STRING);
56
RTStrPrintf(szRev, sizeof(szRev), "%d", VBOX_SVN_REV);
57
rc = RTStrDupEx(ppszRev, szRev);
59
rc = RTStrDupEx(ppszRev, RT_XSTR(VBOX_SVN_REV));
71
return VERR_NO_STR_MEMORY;
69
RTStrFree(*ppszVerEx);
78
81
#ifdef RT_OS_WINDOWS
80
84
* Looks up the storage path handle (registry).
82
86
* @returns IPRT status value
83
* @param hKey Receives pointer of allocated version string. NULL is
84
* accepted. The returned pointer must be closed by
85
* vbglR3CloseAdditionsWinStoragePath().
87
* @param hKey Receives storage path handle on success.
88
* The returned handle must be closed by vbglR3CloseAdditionsWinStoragePath().
87
static int vbglR3GetAdditionsWinStoragePath(PHKEY phKey)
90
static int vbglR3QueryAdditionsWinStoragePath(PHKEY phKey)
90
93
* Try get the *installed* version first.
182
* Queries a string value from a specified registry key.
184
* @return IPRT status code.
185
* @param hKey Handle of registry key to use.
186
* @param pszValName Value name to query value from.
187
* @param pszBuffer Pointer to buffer which the queried string value gets stored into.
188
* @param cchBuffer Size (in bytes) of buffer.
190
static int vbglR3QueryRegistryString(HKEY hKey, const char *pszValName, char *pszBuffer, size_t cchBuffer)
192
AssertReturn(pszValName, VERR_INVALID_PARAMETER);
193
AssertReturn(pszBuffer, VERR_INVALID_POINTER);
194
AssertReturn(cchBuffer, VERR_INVALID_PARAMETER);
198
DWORD dwSize = (DWORD)cchBuffer;
199
LONG lRet = RegQueryValueEx(hKey, pszValName, NULL, &dwType, (BYTE *)pszBuffer, &dwSize);
200
if (lRet == ERROR_SUCCESS)
201
rc = dwType == REG_SZ ? VINF_SUCCESS : VERR_INVALID_PARAMETER;
203
rc = RTErrConvertFromWin32(lRet);
207
#endif /* RT_OS_WINDOWS */
177
210
* Retrieves the installed Guest Additions version and/or revision.
180
213
* @param ppszVer Receives pointer of allocated raw version string
181
214
* (major.minor.build). NULL is accepted. The returned
182
215
* pointer must be freed using RTStrFree().*
183
* @param ppszVerEx Receives pointer of allocated full version string
216
* @param ppszVerExt Receives pointer of allocated full version string
184
217
* (raw version + vendor suffix(es)). NULL is
185
218
* accepted. The returned pointer must be freed using
188
221
* accepted. The returned pointer must be freed using
191
VBGLR3DECL(int) VbglR3GetAdditionsVersion(char **ppszVer, char **ppszVerEx, char **ppszRev)
224
VBGLR3DECL(int) VbglR3GetAdditionsVersion(char **ppszVer, char **ppszVerExt, char **ppszRev)
227
* Zap the return value up front.
193
236
#ifdef RT_OS_WINDOWS
195
int rc = vbglR3GetAdditionsWinStoragePath(&hKey);
238
int rc = vbglR3QueryAdditionsWinStoragePath(&hKey);
196
239
if (RT_SUCCESS(rc))
205
pszTmp = (char*)RTMemAlloc(dwSize);
208
l = RegQueryValueEx(hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
209
if (l == ERROR_SUCCESS)
211
if (dwType == REG_SZ)
212
rc = RTStrDupEx(ppszVer, pszTmp);
214
rc = VERR_INVALID_PARAMETER;
218
rc = RTErrConvertFromWin32(l);
227
dwSize = 32; /* Reset */
228
pszTmp = (char*)RTMemAlloc(dwSize);
231
l = RegQueryValueEx(hKey, "VersionEx", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
232
if (l == ERROR_SUCCESS)
234
if (dwType == REG_SZ)
235
rc = RTStrDupEx(ppszVerEx, pszTmp);
237
rc = VERR_INVALID_PARAMETER;
241
rc = RTErrConvertFromWin32(l);
251
dwSize = 32; /* Reset */
252
pszTmp = (char*)RTMemAlloc(dwSize);
255
l = RegQueryValueEx(hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
256
if (l == ERROR_SUCCESS)
258
if (dwType == REG_SZ)
259
rc = RTStrDupEx(ppszRev, pszTmp);
261
rc = VERR_INVALID_PARAMETER;
265
rc = RTErrConvertFromWin32(l);
272
if (RT_FAILURE(rc) && ppszVer)
247
rc = vbglR3QueryRegistryString(hKey, "Version", szTemp, sizeof(szTemp));
249
rc = RTStrDupEx(ppszVer, szTemp);
255
rc = vbglR3QueryRegistryString(hKey, "VersionExt", szTemp, sizeof(szTemp));
257
rc = RTStrDupEx(ppszVerExt, szTemp);
266
rc = vbglR3QueryRegistryString(hKey, "Revision", szTemp, sizeof(szTemp));
268
rc = RTStrDupEx(ppszRev, szTemp);
271
int rc2 = vbglR3CloseAdditionsWinStoragePath(hKey);
275
/* Clean up allocated strings on error. */
274
279
RTStrFree(*ppszVer);
281
RTStrFree(*ppszVerExt);
278
rc = vbglR3CloseAdditionsWinStoragePath(hKey);
292
298
* On non-Windows platforms just return the compile-time version string.
294
return vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerEx, ppszRev);
300
return vbglR3GetAdditionsCompileTimeVersion(ppszVer, ppszVerExt, ppszRev);
295
301
#endif /* !RT_OS_WINDOWS */