SETUPAPI: implement SetupDiGetINFClass

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

SETUPAPI: implement SetupDiGetINFClass

Hans Leidekker

Code by Hervé Poussineau from ReactOS, with slight modifications
for Wine and A->W conversion by me.

Fixes http://bugs.winehq.org/show_bug.cgi?id=2223

 -Hans

Changelog
  Hervé Poussineau <[hidden email]>
  Implement SetupDiGetINFClass.

Index: include/setupapi.h
===================================================================
RCS file: /home/wine/wine/include/setupapi.h,v
retrieving revision 1.28
diff -u -p -r1.28 setupapi.h
--- include/setupapi.h 21 Sep 2005 14:12:28 -0000 1.28
+++ include/setupapi.h 16 Oct 2005 09:47:26 -0000
@@ -762,6 +762,9 @@ BOOL     WINAPI SetupDiGetDeviceInstallP
 BOOL     WINAPI SetupDiGetDeviceInstallParamsW(HDEVINFO, PSP_DEVINFO_DATA, PSP_DEVINSTALL_PARAMS_W);
 #define         SetupDiGetDeviceInstallParams WINELIB_NAME_AW(SetupDiGetDeviceInstallParams)
 BOOL     WINAPI SetupDiGetDeviceRegistryPropertyA(HDEVINFO, PSP_DEVINFO_DATA, DWORD, PDWORD, PBYTE, DWORD, PDWORD);
+BOOL     WINAPI SetupDiGetINFClassA(PCSTR, LPGUID, PSTR, DWORD, PDWORD);
+BOOL     WINAPI SetupDiGetINFClassW(PCWSTR, LPGUID, PWSTR, DWORD, PDWORD);
+#define         SetupDiGetINFClass WINELIB_NAME_AW(SetupDiGetINFClass)
 BOOL     WINAPI SetupDiInstallClassA(HWND, PCSTR, DWORD, HSPFILEQ);
 BOOL     WINAPI SetupDiInstallClassW(HWND, PCWSTR, DWORD, HSPFILEQ);
 #define         SetupDiInstallClass WINELIB_NAME_AW(SetupDiInstallClass)
Index: dlls/setupapi/devinst.c
===================================================================
RCS file: /home/wine/wine/dlls/setupapi/devinst.c,v
retrieving revision 1.26
diff -u -p -r1.26 devinst.c
--- dlls/setupapi/devinst.c 6 Sep 2005 11:42:51 -0000 1.26
+++ dlls/setupapi/devinst.c 16 Oct 2005 09:47:31 -0000
@@ -1151,6 +1151,113 @@ BOOL WINAPI SetupDiGetDeviceRegistryProp
 }
 
 /***********************************************************************
+ *      SetupDiGetINFClassA    (SETUPAPI.@)
+ */
+BOOL WINAPI SetupDiGetINFClassA( IN PCSTR InfName, OUT LPGUID ClassGuid,
+    OUT PSTR ClassName, IN DWORD ClassNameSize, OUT PDWORD RequiredSize OPTIONAL)
+{
+    LPWSTR InfNameW, ClassNameW;
+    BOOL ret = FALSE;
+
+    TRACE("%s %p %p %ld %p\n", debugstr_a(InfName), ClassGuid,
+          ClassName, ClassNameSize, RequiredSize);
+
+    if (InfName)
+    {
+        int len = MultiByteToWideChar(CP_ACP, 0, InfName, -1, NULL, 0);
+
+        InfNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+        if (!InfNameW) return FALSE;
+        MultiByteToWideChar(CP_ACP, 0, InfName, -1, InfNameW, len);
+    }
+
+    ret = SetupDiGetINFClassW(InfNameW, ClassGuid, ClassNameW, ClassNameSize, RequiredSize);
+    HeapFree(GetProcessHeap(), 0, InfNameW);
+
+    if (ret)
+    {
+        int len = WideCharToMultiByte(CP_ACP, 0, ClassNameW, -1, ClassName, ClassNameSize, NULL, NULL);
+        if (!len) ret = FALSE;
+    }
+    return ret;
+}
+
+/***********************************************************************
+ *      SetupDiGetINFClassW    (SETUPAPI.@)
+ */
+BOOL WINAPI SetupDiGetINFClassW( IN PCWSTR InfName, OUT LPGUID ClassGuid,
+    OUT PWSTR ClassName, IN DWORD ClassNameSize, OUT PDWORD RequiredSize OPTIONAL)
+{
+    HINF hInf = INVALID_HANDLE_VALUE;
+    DWORD requiredSize;
+    WCHAR guidW[MAX_GUID_STRING_LEN + 1];
+    static const GUID nullguid = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };
+    BOOL ret = FALSE;
+
+    TRACE("%s %p %p %ld %p\n", debugstr_w(InfName), ClassGuid,
+          ClassName, ClassNameSize, RequiredSize);
+
+    /* Open .inf file */
+    hInf = SetupOpenInfFileW(InfName, NULL, INF_STYLE_WIN4, NULL);
+    if (hInf == INVALID_HANDLE_VALUE)
+        goto cleanup;
+
+    /* Read class Guid */
+    if (!SetupGetLineTextW(NULL, hInf, Version, ClassGUID, guidW, sizeof(guidW), NULL))
+        goto cleanup;
+    guidW[37] = '\0'; /* Replace the } by a NULL character */
+    if (UuidFromStringW(&guidW[1], ClassGuid) != RPC_S_OK)
+        goto cleanup;
+
+    /* Read class name */
+    ret = SetupGetLineTextW(NULL, hInf, Version, Class, ClassName, ClassNameSize, &requiredSize);
+    if (ret && ClassName == NULL && ClassNameSize == 0)
+    {
+        if (RequiredSize)
+            *RequiredSize = requiredSize;
+        SetLastError(ERROR_INSUFFICIENT_BUFFER);
+        ret = FALSE;
+        goto cleanup;
+    }
+    if (!ret)
+    {
+        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+        {
+            if (RequiredSize)
+                *RequiredSize = requiredSize;
+            goto cleanup;
+        }
+        else if (!SetupDiClassNameFromGuidW(ClassGuid, ClassName, ClassNameSize, &requiredSize))
+        {
+            if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+            {
+                if (RequiredSize)
+                    *RequiredSize = requiredSize;
+                goto cleanup;
+            }
+            /* Return a NULL class name */
+            if (RequiredSize)
+                *RequiredSize = 1;
+            if (ClassNameSize < 1)
+            {
+                SetLastError(ERROR_INSUFFICIENT_BUFFER);
+                goto cleanup;
+            }
+            memcpy(ClassGuid, &nullguid, sizeof(GUID));
+            *ClassName = '\0';
+        }
+    }
+    ret = TRUE;
+
+cleanup:
+    if (hInf != INVALID_HANDLE_VALUE)
+        SetupCloseInfFile(hInf);
+
+    TRACE("Returning %d\n", ret);
+    return ret;
+}
+
+/***********************************************************************
  * SetupDiInstallClassA (SETUPAPI.@)
  */
 BOOL WINAPI SetupDiInstallClassA(
Index: dlls/setupapi/setupapi.spec
===================================================================
RCS file: /home/wine/wine/dlls/setupapi/setupapi.spec,v
retrieving revision 1.43
diff -u -p -r1.43 setupapi.spec
--- dlls/setupapi/setupapi.spec 21 Sep 2005 14:12:15 -0000 1.43
+++ dlls/setupapi/setupapi.spec 16 Oct 2005 09:47:31 -0000
@@ -341,8 +341,8 @@
 @ stub SetupDiGetHwProfileList
 @ stub SetupDiGetHwProfileListExA
 @ stub SetupDiGetHwProfileListExW
-@ stub SetupDiGetINFClassA
-@ stub SetupDiGetINFClassW
+@ stdcall SetupDiGetINFClassA(str ptr ptr long ptr)
+@ stdcall SetupDiGetINFClassW(wstr ptr ptr long ptr)
 @ stub SetupDiGetSelectedDevice
 @ stub SetupDiGetSelectedDriverA
 @ stub SetupDiGetSelectedDriverW