ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

hwprofiles.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS system libraries
00004  * FILE:            dll/win32/advapi32/misc/hwprofiles.c
00005  * PURPOSE:         advapi32.dll Hardware Functions
00006  * PROGRAMMER:      Steven Edwards
00007  *                  Eric Kohl
00008  */
00009 
00010 #include <advapi32.h>
00011 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
00012 
00013 /******************************************************************************
00014  * GetCurrentHwProfileA [ADVAPI32.@]
00015  *
00016  * Get the current hardware profile.
00017  *
00018  * PARAMS
00019  *  lpHwProfileInfo [O] Destination for hardware profile information.
00020  *
00021  * RETURNS
00022  *  Success: TRUE. lpHwProfileInfo is updated with the hardware profile details.
00023  *  Failure: FALSE.
00024  *
00025  * @implemented
00026  */
00027 BOOL WINAPI
00028 GetCurrentHwProfileA(LPHW_PROFILE_INFOA lpHwProfileInfo)
00029 {
00030     HW_PROFILE_INFOW ProfileInfo;
00031     UNICODE_STRING StringU;
00032     ANSI_STRING StringA;
00033     BOOL bResult;
00034     NTSTATUS Status;
00035 
00036     TRACE("GetCurrentHwProfileA() called\n");
00037 
00038     bResult = GetCurrentHwProfileW(&ProfileInfo);
00039     if (bResult == FALSE)
00040         return FALSE;
00041 
00042     lpHwProfileInfo->dwDockInfo = ProfileInfo.dwDockInfo;
00043 
00044     /* Convert the profile GUID to ANSI */
00045     StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileGuid;
00046     StringU.Length = wcslen(ProfileInfo.szHwProfileGuid) * sizeof(WCHAR);
00047     StringU.MaximumLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR);
00048     StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileGuid;
00049     StringA.Length = 0;
00050     StringA.MaximumLength = HW_PROFILE_GUIDLEN;
00051     Status = RtlUnicodeStringToAnsiString(&StringA,
00052                                           &StringU,
00053                                           FALSE);
00054     if (!NT_SUCCESS(Status))
00055     {
00056         SetLastError(RtlNtStatusToDosError(Status));
00057         return FALSE;
00058     }
00059 
00060     /* Convert the profile name to ANSI */
00061     StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileName;
00062     StringU.Length = wcslen(ProfileInfo.szHwProfileName) * sizeof(WCHAR);
00063     StringU.MaximumLength = MAX_PROFILE_LEN * sizeof(WCHAR);
00064     StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileName;
00065     StringA.Length = 0;
00066     StringA.MaximumLength = MAX_PROFILE_LEN;
00067     Status = RtlUnicodeStringToAnsiString(&StringA,
00068                                           &StringU,
00069                                           FALSE);
00070     if (!NT_SUCCESS(Status))
00071     {
00072         SetLastError(RtlNtStatusToDosError(Status));
00073         return FALSE;
00074     }
00075 
00076     return TRUE;
00077 }
00078 
00079 
00080 /*
00081  * @implemented
00082  */
00083 BOOL WINAPI
00084 GetCurrentHwProfileW(LPHW_PROFILE_INFOW lpHwProfileInfo)
00085 {
00086     WCHAR szKeyName[256];
00087     HKEY hDbKey;
00088     HKEY hProfileKey;
00089     DWORD dwLength;
00090     DWORD dwConfigId;
00091     UUID uuid;
00092 
00093     TRACE("GetCurrentHwProfileW() called\n");
00094 
00095     if (lpHwProfileInfo == NULL)
00096     {
00097         SetLastError(ERROR_INVALID_PARAMETER);
00098         return FALSE;
00099     }
00100 
00101     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
00102                       L"System\\CurrentControlSet\\Control\\IDConfigDB",
00103                       0,
00104                       KEY_QUERY_VALUE,
00105                       &hDbKey))
00106     {
00107         SetLastError(ERROR_REGISTRY_CORRUPT);
00108         return FALSE;
00109     }
00110 
00111     dwLength = sizeof(DWORD);
00112     if (RegQueryValueExW(hDbKey,
00113                          L"CurrentConfig",
00114                          0,
00115                          NULL,
00116                          (LPBYTE)&dwConfigId,
00117                          &dwLength))
00118     {
00119         RegCloseKey(hDbKey);
00120         SetLastError(ERROR_REGISTRY_CORRUPT);
00121         return FALSE;
00122     }
00123 
00124     swprintf(szKeyName,
00125              L"Hardware Profile\\%04lu",
00126              dwConfigId);
00127 
00128     if (RegOpenKeyExW(hDbKey,
00129                       szKeyName,
00130                       0,
00131                       KEY_QUERY_VALUE | KEY_SET_VALUE,
00132                       &hProfileKey))
00133     {
00134         RegCloseKey(hDbKey);
00135         SetLastError(ERROR_REGISTRY_CORRUPT);
00136         return FALSE;
00137     }
00138 
00139     dwLength = sizeof(DWORD);
00140     if (RegQueryValueExW(hProfileKey,
00141                          L"DockState",
00142                          0,
00143                          NULL,
00144                          (LPBYTE)&lpHwProfileInfo->dwDockInfo,
00145                          &dwLength))
00146     {
00147         lpHwProfileInfo->dwDockInfo =
00148             DOCKINFO_DOCKED | DOCKINFO_UNDOCKED | DOCKINFO_USER_SUPPLIED;
00149     }
00150 
00151     dwLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR);
00152     if (RegQueryValueExW(hProfileKey,
00153                          L"HwProfileGuid",
00154                          0,
00155                          NULL,
00156                          (LPBYTE)&lpHwProfileInfo->szHwProfileGuid,
00157                          &dwLength))
00158     {
00159         /* Create a new GUID */
00160         UuidCreate(&uuid);
00161         swprintf(
00162             lpHwProfileInfo->szHwProfileGuid,
00163             L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
00164             uuid.Data1, 
00165             uuid.Data2, 
00166             uuid.Data3,
00167             uuid.Data4[0], uuid.Data4[1],
00168             uuid.Data4[2], uuid.Data4[3], uuid.Data4[4], uuid.Data4[5], 
00169             uuid.Data4[6], uuid.Data4[7]);
00170 
00171         dwLength = (wcslen(lpHwProfileInfo->szHwProfileGuid) + 1) * sizeof(WCHAR);
00172         RegSetValueExW(hProfileKey,
00173                        L"HwProfileGuid",
00174                        0,
00175                        REG_SZ,
00176                        (LPBYTE)lpHwProfileInfo->szHwProfileGuid,
00177                        dwLength);
00178     }
00179 
00180     dwLength = MAX_PROFILE_LEN * sizeof(WCHAR);
00181     if (RegQueryValueExW(hProfileKey,
00182                          L"FriendlyName",
00183                          0,
00184                          NULL,
00185                          (LPBYTE)&lpHwProfileInfo->szHwProfileName,
00186                          &dwLength))
00187     {
00188         wcscpy(lpHwProfileInfo->szHwProfileName,
00189                L"Noname Hardware Profile");
00190         dwLength = (wcslen(lpHwProfileInfo->szHwProfileName) + 1) * sizeof(WCHAR);
00191         RegSetValueExW(hProfileKey,
00192                        L"FriendlyName",
00193                        0,
00194                        REG_SZ,
00195                        (LPBYTE)lpHwProfileInfo->szHwProfileName,
00196                        dwLength);
00197     }
00198 
00199     RegCloseKey(hProfileKey);
00200     RegCloseKey(hDbKey);
00201 
00202     return TRUE;
00203 }
00204 
00205 /* EOF */

Generated on Sat May 26 2012 04:21:10 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.