Microsoft KB Archive/237387

{|
 * width="100%"|

BUG: Getting ERROR_INTERNAL_ERROR from GetCurrentHwProfile.

 * }

Q237387

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), included with:
 * Microsoft Windows NT Server version 4.0
 * Microsoft Windows NT Workstation version 4.0

-

SYMPTOMS
The GetCurrentHwProfile API sometimes returns the following error:

ERROR_INTERNAL_ERROR.

CAUSE
The GetCurrentHwProfile API is designed to retrieve hardware profile information stored in the registry:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\IDConfigDB\Hardware Profiles. Sometimes, when the hardware profile is not correctly setup, one or more entries can be missing from the registry, particularly the HwProfileGuid value.

If the HwProfileGuid value does not exist or contains an empty string, and the computer does not contain a properly configured network card, the GetCurrentHwProfile API attempts to create HwProfileGuid value. Because the computer does not have a properly configured network card, the attempt to create a Globally Unique Identifier (GUID) fails, and instead a Locally Unique Identifier (LUID) is created.

When this happens, GetCurrentHwProfile returns the following error message:

ERROR_INTERNAL_ERROR

This error message does not need to be returned because the UID is not required to be globally unique. In other words, the API should go on using the LUID and return success.

RESOLUTION
The work around is to either manually add the value into the registry yourself, or programmatically check for this condition and fix it before calling the API.

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

MORE INFORMATION
The following information shows how to programmatically check and fix the registry value before calling the API.

  #define _WIN32_WINNT 0x4000

#include   #include    #include 

void _tmain (void) {  HKEY hKey = NULL; HKEY hCfgKey = NULL;

__try {     HW_PROFILE_INFO HwProfile; ULONG ulCurrentConfig = 1; ULONG ulSize = 0; UUID NewGuid; TCHAR RegStr[MAX_PATH];

TCHAR pszRegIDConfigDB[] =   TEXT("System\\CurrentControlSet\\Control\\IDConfigDB"); TCHAR pszRegKnownDockingStates[] = TEXT("Hardware Profiles"); TCHAR pszRegCurrentConfig[] = TEXT("CurrentConfig"); TCHAR pszRegHwProfileGuid[] = TEXT("HwProfileGuid"); UCHAR * pszUuidString;

// Initialize to all 0s. ZeroMemory(&HwProfile, sizeof(HwProfile));

// Open IDConfigDB key. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, pszRegIDConfigDB, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) {        __leave; }

// Get current profile sub-key value. ulSize = sizeof(ULONG); if (RegQueryValueEx(hKey, pszRegCurrentConfig, NULL, NULL, (LPBYTE)&ulCurrentConfig, &ulSize) !=   ERROR_SUCCESS) {        __leave; }

// Open current profile sub-key. wsprintf(RegStr, TEXT("%s\\%04u"), pszRegKnownDockingStates,   ulCurrentConfig); if (RegOpenKeyEx(hKey, RegStr, 0, KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_WRITE,   &hCfgKey) != ERROR_SUCCESS) {        __leave; }

// See if HwProfileGuid value exists? ulSize = HW_PROFILE_GUIDLEN * sizeof(TCHAR); if (RegQueryValueEx(hCfgKey, pszRegHwProfileGuid, NULL, NULL, (LPBYTE)&HwProfile.szHwProfileGuid, &ulSize) !=   ERROR_SUCCESS ||                          HwProfile.szHwProfileGuid[0] == TEXT('\0')) {                 RPC_STATUS status;

// Create a UID for the HwProfileGuid value. if (((status = UuidCreate(&NewGuid)) != RPC_S_OK) &&             (status != RPC_S_UUID_LOCAL_ONLY)) {           __leave; }

// Convert the UID to registry entry form. if (UuidToString(&NewGuid, &pszUuidString) == RPC_S_OK) {           lstrcpy((LPBYTE)&HwProfile.szHwProfileGuid, TEXT("{")); lstrcat((LPBYTE)&HwProfile.szHwProfileGuid, pszUuidString); lstrcat((LPBYTE)&HwProfile.szHwProfileGuid, TEXT("}")); _strupr((LPBYTE)&HwProfile.szHwProfileGuid); RpcStringFree(&pszUuidString); }

// Create or set the HwProfileGuid value. ulSize = (lstrlen(HwProfile.szHwProfileGuid) + 1) * sizeof(TCHAR); if (RegSetValueEx(hCfgKey, pszRegHwProfileGuid, 0, REG_SZ, (LPBYTE)HwProfile.szHwProfileGuid, ulSize) !=   ERROR_SUCCESS) {           __leave; }     }

// Get current hardware profile. if (GetCurrentHwProfile(&HwProfile)) {        _tprintf(TEXT("DockInfo = %d\n"), HwProfile.dwDockInfo); _tprintf(TEXT("Profile Guid = %s\n"), HwProfile.szHwProfileGuid); _tprintf(TEXT("Friendly Name = %s\n"), HwProfile.szHwProfileName); }     else {        _tprintf(TEXT("Error [0x%x]: GetCurrentHwProfile failed.\n"),    GetLastError); }  }

__finally {     // Close any open key. if (hCfgKey) RegCloseKey(hCfgKey);

if (hKey) RegCloseKey(hKey); }

return; } Additional query words:

Keywords : kbAPI kbKernBase kbSDKPlatform kbDSupport kbGrpDSKernBase

Issue type : kbbug

Technology : kbAudDeveloper kbWin32sSearch kbWin32API