+ WCHAR szKeyName[256];
+ HKEY hDbKey;
+ HKEY hProfileKey;
+ DWORD dwLength;
+ DWORD dwConfigId;
+
+ DPRINT("GetCurrentHwProfileW() called\n");
+
+ if (lpHwProfileInfo == NULL)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+ L"System\\CurrentControlSet\\Control\\IDConfigDB",
+ 0,
+ KEY_QUERY_VALUE,
+ &hDbKey))
+ {
+ SetLastError(ERROR_REGISTRY_CORRUPT);
+ return FALSE;
+ }
+
+ dwLength = sizeof(DWORD);
+ if (RegQueryValueExW(hDbKey,
+ L"CurrentConfig",
+ 0,
+ NULL,
+ (LPBYTE)&dwConfigId,
+ &dwLength))
+ {
+ RegCloseKey(hDbKey);
+ SetLastError(ERROR_REGISTRY_CORRUPT);
+ return FALSE;
+ }
+
+ swprintf(szKeyName,
+ L"Hardware Profile\\%04lu",
+ dwConfigId);
+
+ if (RegOpenKeyExW(hDbKey,
+ szKeyName,
+ 0,
+ KEY_QUERY_VALUE | KEY_SET_VALUE,
+ &hProfileKey))
+ {
+ RegCloseKey(hDbKey);
+ SetLastError(ERROR_REGISTRY_CORRUPT);
+ return FALSE;
+ }
+
+ dwLength = sizeof(DWORD);
+ if (RegQueryValueExW(hProfileKey,
+ L"DockState",
+ 0,
+ NULL,
+ (LPBYTE)&lpHwProfileInfo->dwDockInfo,
+ &dwLength))
+ {
+ lpHwProfileInfo->dwDockInfo =
+ DOCKINFO_DOCKED | DOCKINFO_UNDOCKED | DOCKINFO_USER_SUPPLIED;
+ }
+
+ dwLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR);
+ if (RegQueryValueExW(hProfileKey,
+ L"HwProfileGuid",
+ 0,
+ NULL,
+ (LPBYTE)&lpHwProfileInfo->szHwProfileGuid,
+ &dwLength))
+ {
+ /* FIXME: Create a new GUID */
+ wcscpy(lpHwProfileInfo->szHwProfileGuid,
+ L"{00000000-0000-0000-0000-000000000000}");
+
+ dwLength = (wcslen(lpHwProfileInfo->szHwProfileGuid) + 1) * sizeof(WCHAR);
+ RegSetValueExW(hProfileKey,
+ L"HwProfileGuid",
+ 0,
+ REG_SZ,
+ (LPBYTE)lpHwProfileInfo->szHwProfileGuid,
+ dwLength);
+ }
+
+ dwLength = MAX_PROFILE_LEN * sizeof(WCHAR);
+ if (RegQueryValueExW(hProfileKey,
+ L"FriendlyName",
+ 0,
+ NULL,
+ (LPBYTE)&lpHwProfileInfo->szHwProfileName,
+ &dwLength))
+ {
+ wcscpy(lpHwProfileInfo->szHwProfileName,
+ L"Noname Hardware Profile");
+ dwLength = (wcslen(lpHwProfileInfo->szHwProfileName) + 1) * sizeof(WCHAR);
+ RegSetValueExW(hProfileKey,
+ L"FriendlyName",
+ 0,
+ REG_SZ,
+ (LPBYTE)lpHwProfileInfo->szHwProfileName,
+ dwLength);
+ }
+
+ RegCloseKey(hProfileKey);
+ RegCloseKey(hDbKey);
+