2010-05-06 09:44:59 +00:00
|
|
|
/*
|
2004-02-25 23:12:39 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
2010-05-06 09:44:59 +00:00
|
|
|
* FILE: dll/win32/advapi32/misc/hwprofiles.c
|
2004-02-25 23:12:39 +00:00
|
|
|
* PURPOSE: advapi32.dll Hardware Functions
|
|
|
|
* PROGRAMMER: Steven Edwards
|
2010-05-06 09:44:59 +00:00
|
|
|
* Eric Kohl
|
2004-02-25 23:12:39 +00:00
|
|
|
*/
|
2004-08-15 17:03:15 +00:00
|
|
|
|
2005-08-05 10:31:28 +00:00
|
|
|
#include <advapi32.h>
|
2008-02-08 17:04:39 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(advapi);
|
2004-02-25 23:12:39 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GetCurrentHwProfileA [ADVAPI32.@]
|
|
|
|
*
|
|
|
|
* Get the current hardware profile.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2004-10-12 11:56:04 +00:00
|
|
|
* lpHwProfileInfo [O] Destination for hardware profile information.
|
2004-02-25 23:12:39 +00:00
|
|
|
*
|
|
|
|
* RETURNS
|
2004-10-12 11:56:04 +00:00
|
|
|
* Success: TRUE. lpHwProfileInfo is updated with the hardware profile details.
|
2004-02-25 23:12:39 +00:00
|
|
|
* Failure: FALSE.
|
2004-10-12 11:56:04 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
2004-02-25 23:12:39 +00:00
|
|
|
*/
|
2008-11-30 11:42:05 +00:00
|
|
|
BOOL WINAPI
|
2004-10-12 11:56:04 +00:00
|
|
|
GetCurrentHwProfileA(LPHW_PROFILE_INFOA lpHwProfileInfo)
|
2004-02-25 23:12:39 +00:00
|
|
|
{
|
2008-09-20 20:28:23 +00:00
|
|
|
HW_PROFILE_INFOW ProfileInfo;
|
|
|
|
UNICODE_STRING StringU;
|
|
|
|
ANSI_STRING StringA;
|
|
|
|
BOOL bResult;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
TRACE("GetCurrentHwProfileA() called\n");
|
|
|
|
|
|
|
|
bResult = GetCurrentHwProfileW(&ProfileInfo);
|
|
|
|
if (bResult == FALSE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
lpHwProfileInfo->dwDockInfo = ProfileInfo.dwDockInfo;
|
|
|
|
|
|
|
|
/* Convert the profile GUID to ANSI */
|
|
|
|
StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileGuid;
|
|
|
|
StringU.Length = wcslen(ProfileInfo.szHwProfileGuid) * sizeof(WCHAR);
|
|
|
|
StringU.MaximumLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR);
|
|
|
|
StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileGuid;
|
|
|
|
StringA.Length = 0;
|
|
|
|
StringA.MaximumLength = HW_PROFILE_GUIDLEN;
|
|
|
|
Status = RtlUnicodeStringToAnsiString(&StringA,
|
|
|
|
&StringU,
|
|
|
|
FALSE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2004-10-12 11:56:04 +00:00
|
|
|
{
|
2008-09-20 20:28:23 +00:00
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
return FALSE;
|
2004-10-12 11:56:04 +00:00
|
|
|
}
|
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
/* Convert the profile name to ANSI */
|
|
|
|
StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileName;
|
|
|
|
StringU.Length = wcslen(ProfileInfo.szHwProfileName) * sizeof(WCHAR);
|
|
|
|
StringU.MaximumLength = MAX_PROFILE_LEN * sizeof(WCHAR);
|
|
|
|
StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileName;
|
|
|
|
StringA.Length = 0;
|
|
|
|
StringA.MaximumLength = MAX_PROFILE_LEN;
|
|
|
|
Status = RtlUnicodeStringToAnsiString(&StringA,
|
|
|
|
&StringU,
|
|
|
|
FALSE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2004-10-12 11:56:04 +00:00
|
|
|
{
|
2008-09-20 20:28:23 +00:00
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
return FALSE;
|
2004-10-12 11:56:04 +00:00
|
|
|
}
|
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
return TRUE;
|
2004-09-13 12:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-12 11:56:04 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-11-30 11:42:05 +00:00
|
|
|
BOOL WINAPI
|
2004-10-12 11:56:04 +00:00
|
|
|
GetCurrentHwProfileW(LPHW_PROFILE_INFOW lpHwProfileInfo)
|
2004-09-13 12:14:55 +00:00
|
|
|
{
|
2008-09-20 20:28:23 +00:00
|
|
|
WCHAR szKeyName[256];
|
|
|
|
HKEY hDbKey;
|
|
|
|
HKEY hProfileKey;
|
|
|
|
DWORD dwLength;
|
|
|
|
DWORD dwConfigId;
|
2010-05-06 09:44:59 +00:00
|
|
|
UUID uuid;
|
2004-10-12 11:56:04 +00:00
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
TRACE("GetCurrentHwProfileW() called\n");
|
2004-10-12 11:56:04 +00:00
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
if (lpHwProfileInfo == NULL)
|
2004-10-12 11:56:04 +00:00
|
|
|
{
|
2008-09-20 20:28:23 +00:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
2004-10-12 11:56:04 +00:00
|
|
|
}
|
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
L"System\\CurrentControlSet\\Control\\IDConfigDB",
|
|
|
|
0,
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
&hDbKey))
|
2004-10-12 11:56:04 +00:00
|
|
|
{
|
2008-09-20 20:28:23 +00:00
|
|
|
SetLastError(ERROR_REGISTRY_CORRUPT);
|
|
|
|
return FALSE;
|
2004-10-12 11:56:04 +00:00
|
|
|
}
|
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
dwLength = sizeof(DWORD);
|
|
|
|
if (RegQueryValueExW(hDbKey,
|
|
|
|
L"CurrentConfig",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
(LPBYTE)&dwConfigId,
|
|
|
|
&dwLength))
|
2004-10-12 11:56:04 +00:00
|
|
|
{
|
2008-09-20 20:28:23 +00:00
|
|
|
RegCloseKey(hDbKey);
|
|
|
|
SetLastError(ERROR_REGISTRY_CORRUPT);
|
|
|
|
return FALSE;
|
2004-10-12 11:56:04 +00:00
|
|
|
}
|
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
swprintf(szKeyName,
|
|
|
|
L"Hardware Profile\\%04lu",
|
|
|
|
dwConfigId);
|
2004-10-12 11:56:04 +00:00
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
if (RegOpenKeyExW(hDbKey,
|
|
|
|
szKeyName,
|
|
|
|
0,
|
|
|
|
KEY_QUERY_VALUE | KEY_SET_VALUE,
|
|
|
|
&hProfileKey))
|
2004-10-12 11:56:04 +00:00
|
|
|
{
|
2008-09-20 20:28:23 +00:00
|
|
|
RegCloseKey(hDbKey);
|
|
|
|
SetLastError(ERROR_REGISTRY_CORRUPT);
|
|
|
|
return FALSE;
|
2004-10-12 11:56:04 +00:00
|
|
|
}
|
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
dwLength = sizeof(DWORD);
|
|
|
|
if (RegQueryValueExW(hProfileKey,
|
|
|
|
L"DockState",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
(LPBYTE)&lpHwProfileInfo->dwDockInfo,
|
|
|
|
&dwLength))
|
2004-10-12 11:56:04 +00:00
|
|
|
{
|
2008-09-20 20:28:23 +00:00
|
|
|
lpHwProfileInfo->dwDockInfo =
|
|
|
|
DOCKINFO_DOCKED | DOCKINFO_UNDOCKED | DOCKINFO_USER_SUPPLIED;
|
2004-10-12 11:56:04 +00:00
|
|
|
}
|
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
dwLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR);
|
|
|
|
if (RegQueryValueExW(hProfileKey,
|
|
|
|
L"HwProfileGuid",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
(LPBYTE)&lpHwProfileInfo->szHwProfileGuid,
|
|
|
|
&dwLength))
|
2004-10-12 11:56:04 +00:00
|
|
|
{
|
2010-05-06 09:44:59 +00:00
|
|
|
/* Create a new GUID */
|
|
|
|
UuidCreate(&uuid);
|
|
|
|
swprintf(
|
|
|
|
lpHwProfileInfo->szHwProfileGuid,
|
|
|
|
L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
|
|
|
|
uuid.Data1,
|
|
|
|
uuid.Data2,
|
|
|
|
uuid.Data3,
|
|
|
|
uuid.Data4[0], uuid.Data4[1],
|
|
|
|
uuid.Data4[2], uuid.Data4[3], uuid.Data4[4], uuid.Data4[5],
|
|
|
|
uuid.Data4[6], uuid.Data4[7]);
|
2008-09-20 20:28:23 +00:00
|
|
|
|
|
|
|
dwLength = (wcslen(lpHwProfileInfo->szHwProfileGuid) + 1) * sizeof(WCHAR);
|
|
|
|
RegSetValueExW(hProfileKey,
|
|
|
|
L"HwProfileGuid",
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(LPBYTE)lpHwProfileInfo->szHwProfileGuid,
|
|
|
|
dwLength);
|
2004-10-12 11:56:04 +00:00
|
|
|
}
|
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
dwLength = MAX_PROFILE_LEN * sizeof(WCHAR);
|
|
|
|
if (RegQueryValueExW(hProfileKey,
|
|
|
|
L"FriendlyName",
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
(LPBYTE)&lpHwProfileInfo->szHwProfileName,
|
|
|
|
&dwLength))
|
2004-10-12 11:56:04 +00:00
|
|
|
{
|
2008-09-20 20:28:23 +00:00
|
|
|
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);
|
2004-10-12 11:56:04 +00:00
|
|
|
}
|
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
RegCloseKey(hProfileKey);
|
|
|
|
RegCloseKey(hDbKey);
|
2004-10-12 11:56:04 +00:00
|
|
|
|
2008-09-20 20:28:23 +00:00
|
|
|
return TRUE;
|
2004-02-25 23:12:39 +00:00
|
|
|
}
|
2004-10-12 11:56:04 +00:00
|
|
|
|
|
|
|
/* EOF */
|