loader: use Unicode functions from cfgmgr32.lib
authorSlawomir Cygan <slawomir.cygan@intel.com>
Thu, 25 Jan 2018 12:48:54 +0000 (13:48 +0100)
committerLenny Komow <lenny@lunarg.com>
Mon, 12 Feb 2018 20:23:57 +0000 (13:23 -0700)
This change improves loader compatibility with Universal
Windows drivers[1]: do not use removed ANSI-based functions,
use Unicode equivalentsexposed in umbrella[2] library.

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/develop/getting-started-with-universal-drivers
[2] https://msdn.microsoft.com/en-us/library/windows/desktop/mt654039(v=vs.85).aspx

Change-Id: I8ead9c46815d15e1b2f2226eb30110c8efa4ec75

loader/loader.c

index f1bc589..543b965 100644 (file)
@@ -543,15 +543,15 @@ out:
 // *reg_data contains a string list of filenames as pointer.
 // When done using the returned string list, the caller should free the pointer.
 VkResult loaderGetDeviceRegistryFiles(const struct loader_instance *inst, char **reg_data, PDWORD reg_data_size, LPCTSTR value_name) {
-    static const char* softwareComponentGUID = "{5c4c3332-344d-483c-8739-259e934c9cc8}";
-    static const char* displayGUID = "{4d36e968-e325-11ce-bfc1-08002be10318}";
+    static const wchar_t* softwareComponentGUID = L"{5c4c3332-344d-483c-8739-259e934c9cc8}";
+    static const wchar_t* displayGUID = L"{4d36e968-e325-11ce-bfc1-08002be10318}";
     const ULONG flags = CM_GETIDLIST_FILTER_CLASS | CM_GETIDLIST_FILTER_PRESENT;
    
-    char childGuid[MAX_GUID_STRING_LEN + 2]; // +2 for brackets {}
+    wchar_t childGuid[MAX_GUID_STRING_LEN + 2]; // +2 for brackets {}
     ULONG childGuidSize = sizeof(childGuid);
 
     DEVINST devID = 0, childID = 0;
-    char *pDeviceNames = NULL;
+    wchar_t *pDeviceNames = NULL;
     ULONG deviceNamesSize = 0;
     VkResult result = VK_SUCCESS;
     bool found = false;
@@ -563,25 +563,25 @@ VkResult loaderGetDeviceRegistryFiles(const struct loader_instance *inst, char *
 
     // if after obtaining the DeviceNameSize, new device is added start over
     do {
-        CM_Get_Device_ID_List_Size(&deviceNamesSize, displayGUID, flags);
+        CM_Get_Device_ID_List_SizeW(&deviceNamesSize, displayGUID, flags);
 
         if (pDeviceNames != NULL) {
             loader_instance_heap_free(inst, pDeviceNames);
         }
 
-        pDeviceNames = loader_instance_heap_alloc(inst, deviceNamesSize, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+        pDeviceNames = loader_instance_heap_alloc(inst, deviceNamesSize * sizeof(wchar_t), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
         if (pDeviceNames == NULL) {
             loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
                 "loaderGetDeviceRegistryFiles: Failed to allocate space for display device names.");
             result = VK_ERROR_OUT_OF_HOST_MEMORY;
             return result;
         }
-    } while (CM_Get_Device_ID_List(displayGUID, pDeviceNames, deviceNamesSize, flags) == CR_BUFFER_SMALL); 
-    
+    } while (CM_Get_Device_ID_ListW(displayGUID, pDeviceNames, deviceNamesSize, flags) == CR_BUFFER_SMALL);
+
     if (pDeviceNames) {
 
-        for (char *deviceName = pDeviceNames; *deviceName; deviceName += strlen(deviceName) + 1) {
-            CONFIGRET status = CM_Locate_DevNode(&devID, deviceName, CM_LOCATE_DEVNODE_NORMAL);
+        for (wchar_t *deviceName = pDeviceNames; *deviceName; deviceName += wcslen(deviceName) + 1) {
+            CONFIGRET status = CM_Locate_DevNodeW(&devID, deviceName, CM_LOCATE_DEVNODE_NORMAL);
             if (CR_SUCCESS != status) {
                 loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
                     "loaderGetRegistryFiles: failed to open DevNode %s", deviceName);
@@ -622,13 +622,13 @@ VkResult loaderGetDeviceRegistryFiles(const struct loader_instance *inst, char *
             }
 
             do {
-                char buffer[MAX_DEVICE_ID_LEN];
-                CM_Get_Device_ID(childID, buffer, MAX_DEVICE_ID_LEN, 0);
+                wchar_t buffer[MAX_DEVICE_ID_LEN];
+                CM_Get_Device_IDW(childID, buffer, MAX_DEVICE_ID_LEN, 0);
 
                 loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0,
                     "loaderGetRegistryFiles: Opening child device %d - %s", childID, buffer);
 
-                status = CM_Get_DevNode_Registry_Property(childID, CM_DRP_CLASSGUID, NULL, &childGuid, &childGuidSize, 0);
+                status = CM_Get_DevNode_Registry_PropertyW(childID, CM_DRP_CLASSGUID, NULL, &childGuid, &childGuidSize, 0);
                 if (status != CR_SUCCESS) {
                     loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
                         "loaderGetRegistryFiles: unable to obtain GUID for:%d error:%d", childID, status);
@@ -637,7 +637,7 @@ VkResult loaderGetDeviceRegistryFiles(const struct loader_instance *inst, char *
                     continue;
                 }
 
-                if (strcmp(childGuid, softwareComponentGUID) != 0) {
+                if (wcscmp(childGuid, softwareComponentGUID) != 0) {
                     loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0,
                         "loaderGetRegistryFiles: GUID for %d is not SoftwareComponent skipping", childID);
                     continue;