diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2015-09-05 10:23:38 -0700 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2015-09-05 10:23:38 -0700 |
commit | 127250e0cae571afc04524a523798ce60f5f08d6 (patch) | |
tree | e0a4067cb539ce4868a535c03c09bc09da72e692 | |
parent | bf1635b3cb6cd8096f35fb1b0000d263522f191e (diff) | |
download | libusb-127250e0cae571afc04524a523798ce60f5f08d6.tar.gz |
Windows: Fix some build warnings/link issues
* Fix MSVC error C4334 (32-bit bit shift)
* Load User32.dll functions at runtime instead of linking directly
against library (fixes unresovled symbol errors on DDK build)
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r-- | libusb/os/windows_usb.c | 17 | ||||
-rw-r--r-- | libusb/os/windows_usb.h | 5 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
3 files changed, 16 insertions, 8 deletions
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index 56c2ef9..79a9612 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -253,6 +253,9 @@ static int init_dlls(void) DLL_LOAD_PREFIXED(SetupAPI.dll, p, SetupDiOpenDeviceInterfaceRegKey, TRUE); DLL_LOAD_PREFIXED(AdvAPI32.dll, p, RegQueryValueExW, TRUE); DLL_LOAD_PREFIXED(AdvAPI32.dll, p, RegCloseKey, TRUE); + DLL_LOAD_PREFIXED(User32.dll, p, GetMessageA, TRUE); + DLL_LOAD_PREFIXED(User32.dll, p, PeekMessageA, TRUE); + DLL_LOAD_PREFIXED(User32.dll, p, PostThreadMessageA, TRUE); return LIBUSB_SUCCESS; } @@ -1014,8 +1017,8 @@ static int windows_init(struct libusb_context *ctx) } // The process affinity mask is a bitmask where each set bit represents a core on // which this process is allowed to run, so we find the first set bit - for (i = 0; !(affinity & (1 << i)); i++); - affinity = (1 << i); + for (i = 0; !(affinity & (DWORD_PTR)(1 << i)); i++); + affinity = (DWORD_PTR)(1 << i); usbi_dbg("timer thread will run on core #%d", i); @@ -1057,7 +1060,7 @@ init_exit: // Holds semaphore here. if (!concurrent_usage && r != LIBUSB_SUCCESS) { // First init failed? if (timer_thread) { // actually the signal to quit the thread. - if (!PostThreadMessage(timer_thread_id, WM_TIMER_EXIT, 0, 0) || + if (!pPostThreadMessageA(timer_thread_id, WM_TIMER_EXIT, 0, 0) || (WaitForSingleObject(timer_thread, INFINITE) != WAIT_OBJECT_0)) { usbi_warn(ctx, "could not wait for timer thread to quit"); TerminateThread(timer_thread, 1); @@ -1889,7 +1892,7 @@ static void windows_exit(void) if (timer_thread) { // actually the signal to quit the thread. - if (!PostThreadMessage(timer_thread_id, WM_TIMER_EXIT, 0, 0) || + if (!pPostThreadMessageA(timer_thread_id, WM_TIMER_EXIT, 0, 0) || (WaitForSingleObject(timer_thread, INFINITE) != WAIT_OBJECT_0)) { usbi_dbg("could not wait for timer thread to quit"); TerminateThread(timer_thread, 1); @@ -2340,7 +2343,7 @@ unsigned __stdcall windows_clock_gettime_threaded(void* param) // The following call will create this thread's message queue // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms644946.aspx - PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); + pPeekMessageA(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); // Signal windows_init() that we're ready to service requests if (!SetEvent((HANDLE)param)) { @@ -2350,7 +2353,7 @@ unsigned __stdcall windows_clock_gettime_threaded(void* param) // Main loop - wait for requests while (1) { - if (GetMessage(&msg, NULL, WM_TIMER_REQUEST, WM_TIMER_EXIT) == -1) { + if (pGetMessageA(&msg, NULL, WM_TIMER_REQUEST, WM_TIMER_EXIT) == -1) { usbi_err(NULL, "GetMessage failed for timer thread: %s", windows_error_str(0)); return 1; } @@ -2391,7 +2394,7 @@ static int windows_clock_gettime(int clk_id, struct timespec *tp) return LIBUSB_ERROR_NO_MEM; } - if (!PostThreadMessage(timer_thread_id, WM_TIMER_REQUEST, 0, (LPARAM)&request)) { + if (!pPostThreadMessageA(timer_thread_id, WM_TIMER_REQUEST, 0, (LPARAM)&request)) { usbi_err(NULL, "PostThreadMessage failed for timer thread: %s", windows_error_str(0)); CloseHandle(request.event); return LIBUSB_ERROR_OTHER; diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h index dd1ce7f..35fd2f2 100644 --- a/libusb/os/windows_usb.h +++ b/libusb/os/windows_usb.h @@ -338,6 +338,11 @@ DLL_DECLARE_PREFIXED(WINAPI, HKEY, p, SetupDiOpenDeviceInterfaceRegKey, (HDEVINF DLL_DECLARE_PREFIXED(WINAPI, LONG, p, RegQueryValueExW, (HKEY, LPCWSTR, LPDWORD, LPDWORD, LPBYTE, LPDWORD)); DLL_DECLARE_PREFIXED(WINAPI, LONG, p, RegCloseKey, (HKEY)); +/* User32 dependencies */ +DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, GetMessageA, (LPMSG, HWND, UINT, UINT)); +DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, PeekMessageA, (LPMSG, HWND, UINT, UINT, UINT)); +DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, PostThreadMessageA, (DWORD, UINT, WPARAM, LPARAM)); + /* * Windows DDK API definitions. Most of it copied from MinGW's includes */ diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 06f5699..9715511 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11000 +#define LIBUSB_NANO 11001 |