summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libusb/os/windows_usb.c19
-rw-r--r--libusb/os/windows_usb.h86
2 files changed, 51 insertions, 54 deletions
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index bced4ee..d6e9f9d 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -250,6 +250,20 @@ static char* sanitize_path(const char* path)
}
/*
+ * Cfgmgr32 API functions
+ */
+static int Cfgmgr32_init(void)
+{
+ DLL_LOAD(Cfgmgr32.dll, CM_Get_Parent, TRUE);
+ DLL_LOAD(Cfgmgr32.dll, CM_Get_Child, TRUE);
+ DLL_LOAD(Cfgmgr32.dll, CM_Get_Sibling, TRUE);
+ DLL_LOAD(Cfgmgr32.dll, CM_Get_Device_IDA, TRUE);
+ DLL_LOAD(Cfgmgr32.dll, CM_Get_Device_IDW, TRUE);
+
+ return LIBUSB_SUCCESS;
+}
+
+/*
* enumerate interfaces for a specific GUID
*
* Parameters:
@@ -390,6 +404,11 @@ static int windows_init(struct libusb_context *ctx)
struct windows_hcd_priv** _hcd_cur;
TCHAR sem_name[11+1+8]; // strlen(libusb_init)+'\0'+(32-bit hex PID)
+ if (Cfgmgr32_init() != LIBUSB_SUCCESS) {
+ usbi_err(ctx, "could not resolve Cfgmgr32.dll functions");
+ return LIBUSB_ERROR_OTHER;
+ }
+
sprintf(sem_name, "libusb_init%08X", (unsigned int)GetCurrentProcessId()&0xFFFFFFFF);
semaphore = CreateSemaphore(NULL, 1, 1, sem_name);
if (semaphore == NULL) {
diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h
index 11b51a9..fdb8549 100644
--- a/libusb/os/windows_usb.h
+++ b/libusb/os/windows_usb.h
@@ -310,6 +310,32 @@ struct windows_transfer_priv {
/*
+ * API macros - from libusb-win32 1.x
+ */
+#define DLL_DECLARE(api, ret, name, args) \
+ typedef ret (api * __dll_##name##_t)args; __dll_##name##_t name
+
+#define DLL_LOAD(dll, name, ret_on_failure) \
+ do { \
+ HMODULE h = GetModuleHandle(#dll); \
+ if (!h) \
+ h = LoadLibrary(#dll); \
+ if (!h) { \
+ if (ret_on_failure) { return LIBUSB_ERROR_OTHER; } \
+ else { break; } \
+ } \
+ name = (__dll_##name##_t)GetProcAddress(h, #name); \
+ if (name) break; \
+ name = (__dll_##name##_t)GetProcAddress(h, #name "A"); \
+ if (name) break; \
+ name = (__dll_##name##_t)GetProcAddress(h, #name "W"); \
+ if (name) break; \
+ if(ret_on_failure) \
+ return LIBUSB_ERROR_OTHER; \
+ } while(0)
+
+
+/*
* Windows DDK API definitions. Most of it copied from MinGW's includes
*/
typedef DWORD DEVNODE, DEVINST;
@@ -388,32 +414,12 @@ typedef enum _USB_HUB_NODE {
UsbMIParent
} USB_HUB_NODE;
-CMAPI CONFIGRET WINAPI CM_Get_Parent(
- /*OUT*/ PDEVINST pdnDevInst,
- /*IN*/ DEVINST dnDevInst,
- /*IN*/ ULONG ulFlags);
-
-CMAPI CONFIGRET WINAPI CM_Get_Child(
- /*OUT*/ PDEVINST pdnDevInst,
- /*IN*/ DEVINST dnDevInst,
- /*IN*/ ULONG ulFlags);
-
-CMAPI CONFIGRET WINAPI CM_Get_Sibling(
- /*OUT*/ PDEVINST pdnDevInst,
- /*IN*/ DEVINST DevInst,
- /*IN*/ ULONG ulFlags);
-
-CMAPI CONFIGRET WINAPI CM_Get_Device_IDA(
- /*IN*/ DEVINST dnDevInst,
- /*OUT*/ PCHAR Buffer,
- /*IN*/ ULONG BufferLen,
- /*IN*/ ULONG ulFlags);
-
-CMAPI CONFIGRET WINAPI CM_Get_Device_IDW(
- /*IN*/ DEVINST dnDevInst,
- /*OUT*/ PWCHAR Buffer,
- /*IN*/ ULONG BufferLen,
- /*IN*/ ULONG ulFlags);
+/* Cfgmgr32.dll interface */
+DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Parent, (PDEVINST, DEVINST, ULONG));
+DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Child, (PDEVINST, DEVINST, ULONG));
+DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Sibling, (PDEVINST, DEVINST, ULONG));
+DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Device_IDA, (DEVINST, PCHAR, ULONG, ULONG));
+DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Device_IDW, (DEVINST, PWCHAR, ULONG, ULONG));
#ifdef UNICODE
#define CM_Get_Device_ID CM_Get_Device_IDW
@@ -603,34 +609,6 @@ typedef struct _USB_HUB_CAPABILITIES_EX {
#pragma pack(pop)
-
-/*
- * API macros - from libusb-win32 1.x
- */
-
-#define DLL_DECLARE(api, ret, name, args) \
- typedef ret (api * __dll_##name##_t)args; __dll_##name##_t name
-
-#define DLL_LOAD(dll, name, ret_on_failure) \
- do { \
- HMODULE h = GetModuleHandle(#dll); \
- if (!h) \
- h = LoadLibrary(#dll); \
- if (!h) { \
- if (ret_on_failure) { return LIBUSB_ERROR_OTHER; } \
- else { break; } \
- } \
- name = (__dll_##name##_t)GetProcAddress(h, #name); \
- if (name) break; \
- name = (__dll_##name##_t)GetProcAddress(h, #name "A"); \
- if (name) break; \
- name = (__dll_##name##_t)GetProcAddress(h, #name "W"); \
- if (name) break; \
- if(ret_on_failure) \
- return LIBUSB_ERROR_OTHER; \
- } while(0)
-
-
/* winusb.dll interface */
#define SHORT_PACKET_TERMINATE 0x01