http://bugs.winehq.org/show_bug.cgi?id=4468
------- Additional Comments From focht@gmx.net 2007-21-02 06:02 ------- Hello,
i looked at the patch and i think it could be further improved....
- input parameter checking missing (trashes if null ptr) - use of SetLastError() (any "good" app which uses api checks for it)
From looking at my own registry and MSDN (see KB237387 - corrupt hardware
profiles) i would prefer the "current config" approach, e.g. reading the active hardware profile number and then get the subtree data.
The patch assumes there is only one hardware profile ever. Autogenerating missing profile data is good but i would not autogenerate the "base" profile reg tree structure itself in api function. This should be done by some wine setup script. e.g. creating:
"System\CurrentControlSet\Control\IDConfigDB" + CurrentConfig (points to "Hardware Profiles\xxxx" "System\CurrentControlSet\Control\IDConfigDB\CurrentDockInfo + DockingState
A default hw profile "0000" under
"System\CurrentControlSet\Control\IDConfigDB\Hardware Profiles\0000" with at least "FriendlyName" and some "HwProfileGuid" setup (even if fake)
Following is some code how this might work... just to get the idea
--- sample (pseudo) code --- BOOL WINAPI GetCurrentHwProfile(LPHW_PROFILE_INFO pInfo) { HKEY base_key, profile_key, dockinfo_key; DWORD current_config; char profile_keyname[MAX_PATH]; int cnt;
if( pInfo == NULL) { SetLastError( ERROR_INVALID_PARAMETER); return FALSE; }
base_key = profile_key = dockinfo_key = 0;
if( !OpenRegKey( "System\CurrentControlSet\Control\IDConfigDB", &base_key)) { SetLastError( ERROR_REGISTRY_CORRUPT); goto error; }
if( !QueryRegValue( base_key, "CurrentConfig", REG_DWORD, ¤t_config)) { SetLastError( ERROR_REGISTRY_CORRUPT); goto error; }
cnt = snprintf( profile_keyname, sizeof(profile_keyname), "Hardware Profiles\%04u", current_config); if( cnt < 0 || cnt >= sizeof(profile_keyname)) { SetLastError( ERROR_INSUFFICIENT_BUFFER); goto error; }
if( !OpenRegKey( profile_keyname, &profile_key)) { SetLastError( ERROR_REGISTRY_CORRUPT); goto error; }
if( !OpenRegKey( "CurrentDockInfo", &dockinfo_key)) { SetLastError( ERROR_REGISTRY_CORRUPT); goto error; }
if( !QueryRegValue( dockinfo_key, "DockingState", REG_DWORD, &docking_state)) { // fake data (according to MSDN might be better to return DOCKINFO_UNDOCKED (desktop systems) pInfo->dwDockInfo = 1;
// write value to active profile in registry }
if( !QueryRegValue( profile_key, "HwProfileGuid", REG_SZ, pInfo->szHwProfileGuid)) { // see KB237387 (corrupt hardware profiles)
// fake some guid like in patch
// write guid string value to active profile in registry
// copy to pInfo->szHwProfileGuid }
if( !QueryRegValue( profile_key, "FriendlyName", REG_SZ, pInfo->szHwProfileName)) { // fake like in patch strcpy( pInfo->szHwProfileName, "some fake profile");
// write the value to active profile in registry }
return TRUE;
error:
if( dockinfo_key != 0) CloseRegKey( dockinfo_key);
if( profile_key != 0) CloseRegKey( profile_key);
if( base_key != 0) CloseRegKey( base_key);
return FALSE; } --- sample (pseudo) code ---
Regards