From: Pete Batard Date: Tue, 8 Mar 2011 17:18:48 +0000 (+0000) Subject: Windows: explicit use of ANSI or WideChar calls X-Git-Tag: upstream/1.0.21~839 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9da8cf5c9ed9bd381a77d8170fc0556edbcce4dc;p=platform%2Fupstream%2Flibusb.git Windows: explicit use of ANSI or WideChar calls * This is in anticipation of adding MSVC project files that use Unicode rather than MBCS --- diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c index 4eaf328..556ac84 100644 --- a/libusb/os/poll_windows.c +++ b/libusb/os/poll_windows.c @@ -152,7 +152,7 @@ void init_polling(void) } if (!is_polling_set) { pCancelIoEx = (BOOL (__stdcall *)(HANDLE,LPOVERLAPPED)) - GetProcAddress(GetModuleHandle("KERNEL32"), "CancelIoEx"); + GetProcAddress(GetModuleHandleA("KERNEL32"), "CancelIoEx"); usbi_dbg("Will use CancelIo%s for I/O cancellation", CancelIoEx_Available?"Ex":""); for (i=0; icbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); - if (!pSetupDiGetDeviceInterfaceDetail(*dev_info, &dev_interface_data, + dev_interface_details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A); + if (!pSetupDiGetDeviceInterfaceDetailA(*dev_info, &dev_interface_data, dev_interface_details, size, &size, NULL)) { usbi_err(ctx, "could not access interface data (actual) for index %u: %s", _index, windows_error_str(0)); @@ -494,17 +493,17 @@ static void auto_release(struct usbi_transfer *itransfer) static int windows_init(struct libusb_context *ctx) { HDEVINFO dev_info; - SP_DEVICE_INTERFACE_DETAIL_DATA *dev_interface_details = NULL; + SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details = NULL; GUID guid; libusb_bus_t bus; int i, r = LIBUSB_ERROR_OTHER; OSVERSIONINFO os_version; HANDLE semaphore; struct windows_hcd_priv** _hcd_cur; - TCHAR sem_name[11+1+8]; // strlen(libusb_init)+'\0'+(32-bit hex PID) + char sem_name[11+1+8]; // strlen(libusb_init)+'\0'+(32-bit hex PID) sprintf(sem_name, "libusb_init%08X", (unsigned int)GetCurrentProcessId()&0xFFFFFFFF); - semaphore = CreateSemaphore(NULL, 1, 1, sem_name); + semaphore = CreateSemaphoreA(NULL, 1, 1, sem_name); if (semaphore == NULL) { usbi_err(ctx, "could not create semaphore: %s", windows_error_str(0)); return LIBUSB_ERROR_NO_MEM; @@ -1079,7 +1078,7 @@ static int set_composite_device(struct libusb_context *ctx, DEVINST devinst, str CONFIGRET r; HDEVINFO dev_info; SP_DEVINFO_DATA dev_info_data; - SP_DEVICE_INTERFACE_DETAIL_DATA *dev_interface_details = NULL; + SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details = NULL; HKEY key; WCHAR guid_string_w[MAX_GUID_STRING_LENGTH]; GUID guid, class_guid; @@ -1090,7 +1089,7 @@ static int set_composite_device(struct libusb_context *ctx, DEVINST devinst, str char path[MAX_PATH_LENGTH]; char driver[MAX_KEY_LENGTH]; - dev_info = pSetupDiGetClassDevs(NULL, "USB", NULL, DIGCF_PRESENT|DIGCF_ALLCLASSES); + dev_info = pSetupDiGetClassDevsA(NULL, "USB", NULL, DIGCF_PRESENT|DIGCF_ALLCLASSES); if (dev_info == INVALID_HANDLE_VALUE) { return LIBUSB_ERROR_NOT_FOUND; } @@ -1163,7 +1162,7 @@ static int set_composite_device(struct libusb_context *ctx, DEVINST devinst, str pCLSIDFromString(guid_string_w, &class_guid); // Attempt to read the driver string - if(!pSetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_SERVICE, + if(!pSetupDiGetDeviceRegistryPropertyA(dev_info, &dev_info_data, SPDRP_SERVICE, NULL, (BYTE*)driver, MAX_KEY_LENGTH, &size)) { driver[0] = 0; } @@ -1202,7 +1201,7 @@ static int set_composite_device(struct libusb_context *ctx, DEVINST devinst, str break; } - r = CM_Get_Device_ID(child_devinst, path, MAX_PATH_LENGTH, 0); + r = CM_Get_Device_IDA(child_devinst, path, MAX_PATH_LENGTH, 0); if (r != CR_SUCCESS) { usbi_err(ctx, "could not retrieve simple path for interface %d: CR error %d", i, r); @@ -1278,7 +1277,7 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * char path[MAX_PATH_LENGTH]; char *sanitized_path = NULL; HDEVINFO dev_info; - SP_DEVICE_INTERFACE_DETAIL_DATA *dev_interface_details = NULL; + SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details = NULL; SP_DEVINFO_DATA dev_info_data; DEVINST parent_devinst; GUID guid; @@ -1303,7 +1302,7 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * break; // Check that the driver installation is OK - if ( (!pSetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_INSTALL_STATE, + if ( (!pSetupDiGetDeviceRegistryPropertyA(dev_info, &dev_info_data, SPDRP_INSTALL_STATE, ®_type, (BYTE*)&install_state, 4, &size)) || (size != 4) ){ usbi_warn(ctx, "could not detect installation state of driver for %s: %s", @@ -1315,7 +1314,7 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * } // The SPDRP_ADDRESS for USB devices should be the device port number on the hub - if ( (!pSetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_ADDRESS, + if ( (!pSetupDiGetDeviceRegistryPropertyA(dev_info, &dev_info_data, SPDRP_ADDRESS, ®_type, (BYTE*)&port_nr, 4, &size)) || (size != 4) ){ usbi_warn(ctx, "could not retrieve port number for device %s, skipping: %s", @@ -1330,7 +1329,7 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * continue; } - if (CM_Get_Device_ID(parent_devinst, path, MAX_PATH_LENGTH, 0) != CR_SUCCESS) { + if (CM_Get_Device_IDA(parent_devinst, path, MAX_PATH_LENGTH, 0) != CR_SUCCESS) { usbi_warn(ctx, "could not retrieve parent's path for device %s, skipping: %s", dev_interface_details->DevicePath, windows_error_str(0)); continue; @@ -1367,7 +1366,7 @@ static int set_device_paths(struct libusb_context *ctx, struct discovered_devs * // Check the service & filter names to know the API we should use for (k=0; k<3; k++) { - if (pSetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, lookup[k].reg_prop, + if (pSetupDiGetDeviceRegistryPropertyA(dev_info, &dev_info_data, lookup[k].reg_prop, ®_type, (BYTE*)lookup[k].list, MAX_KEY_LENGTH, &size)) { // Turn the REG_SZ SPDRP_SERVICE into REG_MULTI_SZ if (lookup[k].reg_prop == SPDRP_SERVICE) { @@ -1479,10 +1478,10 @@ static void windows_exit(void) struct windows_hcd_priv* hcd_tmp; int i; HANDLE semaphore; - TCHAR sem_name[11+1+8]; // strlen(libusb_init)+'\0'+(32-bit hex PID) + char sem_name[11+1+8]; // strlen(libusb_init)+'\0'+(32-bit hex PID) sprintf(sem_name, "libusb_init%08X", (unsigned int)GetCurrentProcessId()&0xFFFFFFFF); - semaphore = CreateSemaphore(NULL, 1, 1, sem_name); + semaphore = CreateSemaphoreA(NULL, 1, 1, sem_name); if (semaphore == NULL) { return; } diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h index d28b489..5b0eef8 100644 --- a/libusb/os/windows_usb.h +++ b/libusb/os/windows_usb.h @@ -263,9 +263,9 @@ struct driver_lookup { #define DLL_LOAD_PREFIXED(dll, prefix, name, ret_on_failure) \ do { \ - HMODULE h = GetModuleHandle(#dll); \ + HMODULE h = GetModuleHandleA(#dll); \ if (!h) \ - h = LoadLibrary(#dll); \ + h = LoadLibraryA(#dll); \ if (!h) { \ if (ret_on_failure) { return LIBUSB_ERROR_NOT_FOUND; }\ else { break; } \ @@ -287,15 +287,15 @@ struct driver_lookup { DLL_DECLARE_PREFIXED(WINAPI, HRESULT, p, CLSIDFromString, (LPCOLESTR, LPCLSID)); /* SetupAPI dependencies */ -DLL_DECLARE_PREFIXED(WINAPI, HDEVINFO, p, SetupDiGetClassDevs, (const GUID*, PCSTR, HWND, DWORD)); +DLL_DECLARE_PREFIXED(WINAPI, HDEVINFO, p, SetupDiGetClassDevsA, (const GUID*, PCSTR, HWND, DWORD)); DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiEnumDeviceInfo, (HDEVINFO, DWORD, PSP_DEVINFO_DATA)); DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiEnumDeviceInterfaces, (HDEVINFO, PSP_DEVINFO_DATA, const GUID*, DWORD, PSP_DEVICE_INTERFACE_DATA)); -DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiGetDeviceInterfaceDetail, (HDEVINFO, PSP_DEVICE_INTERFACE_DATA, - PSP_DEVICE_INTERFACE_DETAIL_DATA, DWORD, PDWORD, PSP_DEVINFO_DATA)); +DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiGetDeviceInterfaceDetailA, (HDEVINFO, PSP_DEVICE_INTERFACE_DATA, + PSP_DEVICE_INTERFACE_DETAIL_DATA_A, DWORD, PDWORD, PSP_DEVINFO_DATA)); DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiDestroyDeviceInfoList, (HDEVINFO)); DLL_DECLARE_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDevRegKey, (HDEVINFO, PSP_DEVINFO_DATA, DWORD, DWORD, DWORD, REGSAM)); -DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiGetDeviceRegistryProperty, (HDEVINFO, +DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiGetDeviceRegistryPropertyA, (HDEVINFO, PSP_DEVINFO_DATA, DWORD, PDWORD, PBYTE, DWORD, PDWORD)); DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiGetDeviceRegistryPropertyW, (HDEVINFO, PSP_DEVINFO_DATA, DWORD, PDWORD, PBYTE, DWORD, PDWORD)); @@ -380,13 +380,6 @@ 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 -#else -#define CM_Get_Device_ID CM_Get_Device_IDA -#endif /* UNICODE */ #define IOCTL_USB_GET_HUB_CAPABILITIES_EX \ CTL_CODE( FILE_DEVICE_USB, USB_GET_HUB_CAPABILITIES_EX, METHOD_BUFFERED, FILE_ANY_ACCESS)