Maarten Lankhorst : setupapi: Implement CM_Get_Device_ID and add a stub for CM_Get_Parent.

Alexandre Julliard julliard at winehq.org
Sat Mar 1 06:13:21 CST 2008


Module: wine
Branch: master
Commit: ba8642639aa8f682c0b6441b6636d2322c204206
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=ba8642639aa8f682c0b6441b6636d2322c204206

Author: Maarten Lankhorst <m.b.lankhorst at gmail.com>
Date:   Fri Feb 29 17:46:58 2008 -0800

setupapi: Implement CM_Get_Device_ID and add a stub for CM_Get_Parent.

---

 dlls/setupapi/devinst.c     |   80 +++++++++++++++++++++++++++++++++++++++---
 dlls/setupapi/setupapi.spec |    4 +-
 dlls/setupapi/stubs.c       |   21 +++--------
 3 files changed, 81 insertions(+), 24 deletions(-)

diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c
index 0e5aad5..c90170b 100644
--- a/dlls/setupapi/devinst.c
+++ b/dlls/setupapi/devinst.c
@@ -454,13 +454,16 @@ static HKEY SETUPDI_CreateDrvKey(struct DeviceInfo *devInfo)
 static struct DeviceInfo *SETUPDI_AllocateDeviceInfo(struct DeviceInfoSet *set,
         DWORD devId, LPCWSTR instanceId, BOOL phantom)
 {
-    struct DeviceInfo *devInfo = HeapAlloc(GetProcessHeap(), 0,
-            sizeof(struct DeviceInfo));
+    struct DeviceInfo *devInfo = NULL;
+    HANDLE devInst = GlobalAlloc(GMEM_FIXED, sizeof(struct DeviceInfo));
+    if (devInst)
+        devInfo = GlobalLock(devInst);
 
     if (devInfo)
     {
         devInfo->set = set;
-        devInfo->devId = devId;
+        devInfo->devId = (DWORD)devInst;
+
         devInfo->instanceId = HeapAlloc(GetProcessHeap(), 0,
                 (lstrlenW(instanceId) + 1) * sizeof(WCHAR));
         if (devInfo->instanceId)
@@ -477,10 +480,12 @@ static struct DeviceInfo *SETUPDI_AllocateDeviceInfo(struct DeviceInfoSet *set,
                             (LPBYTE)&phantom, sizeof(phantom));
             }
             list_init(&devInfo->interfaces);
+            GlobalUnlock(devInst);
         }
         else
         {
-            HeapFree(GetProcessHeap(), 0, devInfo);
+            GlobalUnlock(devInst);
+            GlobalFree(devInst);
             devInfo = NULL;
         }
     }
@@ -514,7 +519,7 @@ static void SETUPDI_FreeDeviceInfo(struct DeviceInfo *devInfo)
         SETUPDI_FreeInterfaceInstances(iface);
         HeapFree(GetProcessHeap(), 0, iface);
     }
-    HeapFree(GetProcessHeap(), 0, devInfo);
+    GlobalFree((HANDLE)devInfo->devId);
 }
 
 /* Adds a device with GUID guid and identifer devInst to set.  Allocates a
@@ -551,7 +556,7 @@ static BOOL SETUPDI_AddDeviceToSet(struct DeviceInfoSet *set,
 
             DeviceInfoData->cbSize = sizeof(SP_DEVINFO_DATA);
             memcpy(&DeviceInfoData->ClassGuid, guid, sizeof(GUID));
-            DeviceInfoData->DevInst = devInst;
+            DeviceInfoData->DevInst = devInfo->devId;
             DeviceInfoData->Reserved = (ULONG_PTR)devInfo;
             SETUPDI_GuidToString(guid, classGuidStr);
             SetupDiSetDeviceRegistryPropertyW((HDEVINFO)set,
@@ -3848,3 +3853,66 @@ BOOL WINAPI SetupDiDeleteDevRegKey(
     }
     return ret;
 }
+
+/***********************************************************************
+ *              CM_Get_Device_IDA  (SETUPAPI.@)
+ */
+CONFIGRET WINAPI CM_Get_Device_IDA( DEVINST dnDevInst, PSTR Buffer,
+                                   ULONG  BufferLen, ULONG  ulFlags)
+{
+    struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
+
+    TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
+
+    if (!devInfo)
+        return CR_NO_SUCH_DEVINST;
+
+    WideCharToMultiByte(CP_ACP, 0, devInfo->instanceId, -1, Buffer, BufferLen, 0, 0);
+    TRACE("Returning %s\n", debugstr_a(Buffer));
+    return CR_SUCCESS;
+}
+
+/***********************************************************************
+ *              CM_Get_Device_IDW  (SETUPAPI.@)
+ */
+CONFIGRET WINAPI CM_Get_Device_IDW( DEVINST dnDevInst, LPWSTR Buffer,
+                                   ULONG  BufferLen, ULONG  ulFlags)
+{
+    struct DeviceInfo *devInfo = GlobalLock((HANDLE)dnDevInst);
+
+    TRACE("%x->%p, %p, %u %u\n", dnDevInst, devInfo, Buffer, BufferLen, ulFlags);
+
+    if (!devInfo)
+    {
+        WARN("dev instance %d not found!\n", dnDevInst);
+        return CR_NO_SUCH_DEVINST;
+    }
+
+    lstrcpynW(Buffer, devInfo->instanceId, BufferLen);
+    TRACE("Returning %s\n", debugstr_w(Buffer));
+    GlobalUnlock((HANDLE)dnDevInst);
+    return CR_SUCCESS;
+}
+
+
+
+/***********************************************************************
+ *              CM_Get_Device_ID_Size  (SETUPAPI.@)
+ */
+CONFIGRET WINAPI CM_Get_Device_ID_Size( PULONG  pulLen, DEVINST dnDevInst,
+                                        ULONG  ulFlags)
+{
+    struct DeviceInfo *ppdevInfo = GlobalLock((HANDLE)dnDevInst);
+
+    TRACE("%x->%p, %p, %u\n", dnDevInst, ppdevInfo, pulLen, ulFlags);
+
+    if (!ppdevInfo)
+    {
+        WARN("dev instance %d not found!\n", dnDevInst);
+        return CR_NO_SUCH_DEVINST;
+    }
+
+    *pulLen = lstrlenW(ppdevInfo->instanceId);
+    GlobalUnlock((HANDLE)dnDevInst);
+    return CR_SUCCESS;
+}
diff --git a/dlls/setupapi/setupapi.spec b/dlls/setupapi/setupapi.spec
index ab62b6d..5f31721 100644
--- a/dlls/setupapi/setupapi.spec
+++ b/dlls/setupapi/setupapi.spec
@@ -72,7 +72,7 @@
 @ stub CM_Get_DevNode_Status
 @ stub CM_Get_DevNode_Status_Ex
 @ stdcall CM_Get_Device_IDA(ptr ptr long long)
-@ stub CM_Get_Device_IDW
+@ stdcall CM_Get_Device_IDW(ptr ptr long long)
 @ stub CM_Get_Device_ID_ExA
 @ stub CM_Get_Device_ID_ExW
 @ stdcall CM_Get_Device_ID_ListA(ptr ptr long long)
@@ -115,7 +115,7 @@
 @ stub CM_Get_Next_Log_Conf_Ex
 @ stub CM_Get_Next_Res_Des
 @ stub CM_Get_Next_Res_Des_Ex
-@ stub CM_Get_Parent
+@ stdcall CM_Get_Parent(ptr long long)
 @ stub CM_Get_Parent_Ex
 @ stub CM_Get_Res_Des_Data
 @ stub CM_Get_Res_Des_Data_Ex
diff --git a/dlls/setupapi/stubs.c b/dlls/setupapi/stubs.c
index 130973a..a6f7a5b 100644
--- a/dlls/setupapi/stubs.c
+++ b/dlls/setupapi/stubs.c
@@ -28,6 +28,7 @@
 #include "winreg.h"
 #include "cfgmgr32.h"
 #include "setupapi.h"
+#include "winnls.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
 
@@ -70,17 +71,6 @@ CONFIGRET WINAPI CM_Disconnect_Machine(HMACHINE handle)
 }
 
 /***********************************************************************
- *		CM_Get_Device_IDA  (SETUPAPI.@)
- */
-CONFIGRET WINAPI CM_Get_Device_IDA( DEVINST dnDevInst, PSTR Buffer,
-                                   ULONG  BufferLen, ULONG  ulFlags)
-{
-    FIXME("%x, %p, %u %u\n",dnDevInst, Buffer, BufferLen, ulFlags);
-    Buffer[0] = 0;
-    return CR_SUCCESS;
-}
-
-/***********************************************************************
  *             CM_Get_Device_ID_ListA  (SETUPAPI.@)
  */
 
@@ -93,13 +83,12 @@ CONFIGRET WINAPI CM_Get_Device_ID_ListA(
 }
 
 /***********************************************************************
- *		CM_Get_Device_ID_Size  (SETUPAPI.@)
+ *              CM_Get_Parent (SETUPAPI.@)
  */
-CONFIGRET WINAPI CM_Get_Device_ID_Size( PULONG  pulLen, DEVINST dnDevInst,
-                                        ULONG  ulFlags)
+DWORD WINAPI CM_Get_Parent(PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
 {
-    FIXME("%p %x %u\n",pulLen, dnDevInst, ulFlags);
-    *pulLen = 1;
+    FIXME("%p 0x%08x 0x%08x stub\n", pdnDevInst, dnDevInst, ulFlags);
+    *pdnDevInst = dnDevInst;
     return CR_SUCCESS;
 }
 




More information about the wine-cvs mailing list