ReactOS  0.4.13-dev-247-g0f29b3f
hwprofiles.c File Reference
#include <advapi32.h>
Include dependency graph for hwprofiles.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (advapi)
 
BOOL WINAPI GetCurrentHwProfileA (LPHW_PROFILE_INFOA lpHwProfileInfo)
 
BOOL WINAPI GetCurrentHwProfileW (LPHW_PROFILE_INFOW lpHwProfileInfo)
 

Function Documentation

◆ GetCurrentHwProfileA()

BOOL WINAPI GetCurrentHwProfileA ( LPHW_PROFILE_INFOA  lpHwProfileInfo)

Definition at line 28 of file hwprofiles.c.

29 {
30  HW_PROFILE_INFOW ProfileInfo;
31  UNICODE_STRING StringU;
32  ANSI_STRING StringA;
33  BOOL bResult;
35 
36  TRACE("GetCurrentHwProfileA() called\n");
37 
38  bResult = GetCurrentHwProfileW(&ProfileInfo);
39  if (bResult == FALSE)
40  return FALSE;
41 
42  lpHwProfileInfo->dwDockInfo = ProfileInfo.dwDockInfo;
43 
44  /* Convert the profile GUID to ANSI */
45  StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileGuid;
46  StringU.Length = wcslen(ProfileInfo.szHwProfileGuid) * sizeof(WCHAR);
47  StringU.MaximumLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR);
48  StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileGuid;
49  StringA.Length = 0;
52  &StringU,
53  FALSE);
54  if (!NT_SUCCESS(Status))
55  {
57  return FALSE;
58  }
59 
60  /* Convert the profile name to ANSI */
61  StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileName;
62  StringU.Length = wcslen(ProfileInfo.szHwProfileName) * sizeof(WCHAR);
63  StringU.MaximumLength = MAX_PROFILE_LEN * sizeof(WCHAR);
64  StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileName;
65  StringA.Length = 0;
68  &StringU,
69  FALSE);
70  if (!NT_SUCCESS(Status))
71  {
73  return FALSE;
74  }
75 
76  return TRUE;
77 }
#define TRUE
Definition: types.h:120
CHAR szHwProfileName[MAX_PROFILE_LEN]
Definition: winbase.h:1096
USHORT MaximumLength
Definition: env_spec_w32.h:370
CHAR szHwProfileGuid[HW_PROFILE_GUIDLEN]
Definition: winbase.h:1095
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:54
#define MAX_PROFILE_LEN
Definition: cfgmgr32.h:54
#define HW_PROFILE_GUIDLEN
Definition: winbase.h:241
unsigned int BOOL
Definition: ntddk_ex.h:94
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
#define PCHAR
Definition: match.c:90
USHORT MaximumLength
Definition: env_spec_w32.h:377
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
WCHAR szHwProfileGuid[HW_PROFILE_GUIDLEN]
Definition: winbase.h:1101
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
WCHAR szHwProfileName[MAX_PROFILE_LEN]
Definition: winbase.h:1102
BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW lpHwProfileInfo)
Definition: hwprofiles.c:84
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by SHGetMachineInfo().

◆ GetCurrentHwProfileW()

BOOL WINAPI GetCurrentHwProfileW ( LPHW_PROFILE_INFOW  lpHwProfileInfo)

Definition at line 84 of file hwprofiles.c.

85 {
86  WCHAR szKeyName[256];
87  HKEY hDbKey;
88  HKEY hProfileKey;
90  DWORD dwConfigId;
91  UUID uuid;
92 
93  TRACE("GetCurrentHwProfileW() called\n");
94 
95  if (lpHwProfileInfo == NULL)
96  {
98  return FALSE;
99  }
100 
102  L"System\\CurrentControlSet\\Control\\IDConfigDB",
103  0,
105  &hDbKey))
106  {
108  return FALSE;
109  }
110 
111  dwLength = sizeof(DWORD);
112  if (RegQueryValueExW(hDbKey,
113  L"CurrentConfig",
114  0,
115  NULL,
116  (LPBYTE)&dwConfigId,
117  &dwLength))
118  {
119  RegCloseKey(hDbKey);
121  return FALSE;
122  }
123 
124  swprintf(szKeyName,
125  L"Hardware Profile\\%04lu",
126  dwConfigId);
127 
128  if (RegOpenKeyExW(hDbKey,
129  szKeyName,
130  0,
132  &hProfileKey))
133  {
134  RegCloseKey(hDbKey);
136  return FALSE;
137  }
138 
139  dwLength = sizeof(DWORD);
140  if (RegQueryValueExW(hProfileKey,
141  L"DockState",
142  0,
143  NULL,
144  (LPBYTE)&lpHwProfileInfo->dwDockInfo,
145  &dwLength))
146  {
147  lpHwProfileInfo->dwDockInfo =
149  }
150 
151  dwLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR);
152  if (RegQueryValueExW(hProfileKey,
153  L"HwProfileGuid",
154  0,
155  NULL,
156  (LPBYTE)&lpHwProfileInfo->szHwProfileGuid,
157  &dwLength))
158  {
159  /* Create a new GUID */
160  UuidCreate(&uuid);
161  swprintf(
162  lpHwProfileInfo->szHwProfileGuid,
163  L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
164  uuid.Data1,
165  uuid.Data2,
166  uuid.Data3,
167  uuid.Data4[0], uuid.Data4[1],
168  uuid.Data4[2], uuid.Data4[3], uuid.Data4[4], uuid.Data4[5],
169  uuid.Data4[6], uuid.Data4[7]);
170 
171  dwLength = (wcslen(lpHwProfileInfo->szHwProfileGuid) + 1) * sizeof(WCHAR);
172  RegSetValueExW(hProfileKey,
173  L"HwProfileGuid",
174  0,
175  REG_SZ,
176  (LPBYTE)lpHwProfileInfo->szHwProfileGuid,
177  dwLength);
178  }
179 
180  dwLength = MAX_PROFILE_LEN * sizeof(WCHAR);
181  if (RegQueryValueExW(hProfileKey,
182  L"FriendlyName",
183  0,
184  NULL,
185  (LPBYTE)&lpHwProfileInfo->szHwProfileName,
186  &dwLength))
187  {
188  wcscpy(lpHwProfileInfo->szHwProfileName,
189  L"Noname Hardware Profile");
190  dwLength = (wcslen(lpHwProfileInfo->szHwProfileName) + 1) * sizeof(WCHAR);
191  RegSetValueExW(hProfileKey,
192  L"FriendlyName",
193  0,
194  REG_SZ,
195  (LPBYTE)lpHwProfileInfo->szHwProfileName,
196  dwLength);
197  }
198 
199  RegCloseKey(hProfileKey);
200  RegCloseKey(hDbKey);
201 
202  return TRUE;
203 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define DWORD
Definition: nt_native.h:44
#define MAX_PROFILE_LEN
Definition: cfgmgr32.h:54
#define HW_PROFILE_GUIDLEN
Definition: winbase.h:241
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
#define DOCKINFO_USER_SUPPLIED
Definition: winbase.h:245
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4917
#define TRACE(s)
Definition: solgame.cpp:4
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
__wchar_t WCHAR
Definition: xmlstorage.h:180
static DWORD DWORD * dwLength
Definition: fusion.c:83
#define swprintf(buf, format,...)
Definition: sprintf.c:56
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
WCHAR szHwProfileGuid[HW_PROFILE_GUIDLEN]
Definition: winbase.h:1101
RPC_STATUS WINAPI UuidCreate(UUID *Uuid)
Definition: rpcrt4_main.c:306
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
WCHAR szHwProfileName[MAX_PROFILE_LEN]
Definition: winbase.h:1102
Definition: msctf.idl:510
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
#define DOCKINFO_UNDOCKED
Definition: winbase.h:243
#define DOCKINFO_DOCKED
Definition: winbase.h:244
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define ERROR_REGISTRY_CORRUPT
Definition: winerror.h:594
#define REG_SZ
Definition: layer.c:22

Referenced by GetCurrentHwProfileA().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( advapi  )