summaryrefslogtreecommitdiff
path: root/libusb/os
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2020-01-21 15:38:56 -0800
committerChris Dickens <christopher.a.dickens@gmail.com>2020-01-21 15:38:56 -0800
commitde4a59af87bf0b6df04d9f1c9439c957681f5e53 (patch)
tree7857351cd595eaea3459dadda4bfe1a3008a892e /libusb/os
parentf90d07613c7a86eca85df9f8209ce586ce70ecf6 (diff)
downloadlibusb-de4a59af87bf0b6df04d9f1c9439c957681f5e53.tar.gz
Misc: Clean up Visual Studio project files
Commit a9b34d170a ("Adding support for ARM & ARM64 Windows Platform") introduced a dependency on a particular version of the Windows 10 SDK for *all* platforms. This is particularly annoying for most users who will only be building for Windows. Fix this by specifying the SDK dependency only for the ARM/ARM64 platforms and bump to the latest. Commit 77037c4dd6 ("Adds /utf-8 to compile options") added this compiler option to all versions of the Visual Studio project files. This results in a number of warnings with the older versions that don't recognize this option. Fix this by keeping this option only for 2015 and newer. Explicitly specify library dependencies for non-static targets. With a small change in the UsbDk backend we can completely remove all depenencies other than kernel32.lib. Lastly, remove the 'MinimalRebuild' option for 2015 and newer project files as this option is now deprecated and results in a warning for each project. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb/os')
-rw-r--r--libusb/os/windows_usbdk.c46
1 files changed, 41 insertions, 5 deletions
diff --git a/libusb/os/windows_usbdk.c b/libusb/os/windows_usbdk.c
index f65052e..aa48ce2 100644
--- a/libusb/os/windows_usbdk.c
+++ b/libusb/os/windows_usbdk.c
@@ -157,29 +157,65 @@ error_unload:
return LIBUSB_ERROR_NOT_FOUND;
}
+typedef SC_HANDLE (WINAPI *POPENSCMANAGERA)(LPCSTR, LPCSTR, DWORD);
+typedef SC_HANDLE (WINAPI *POPENSERVICEA)(SC_HANDLE, LPCSTR, DWORD);
+typedef BOOL (WINAPI *PCLOSESERVICEHANDLE)(SC_HANDLE);
+
static int usbdk_init(struct libusb_context *ctx)
{
+ POPENSCMANAGERA pOpenSCManagerA;
+ POPENSERVICEA pOpenServiceA;
+ PCLOSESERVICEHANDLE pCloseServiceHandle;
SC_HANDLE managerHandle;
SC_HANDLE serviceHandle;
+ HMODULE h;
+
+ h = LoadLibraryA("Advapi32");
+ if (h == NULL) {
+ usbi_warn(ctx, "failed to open Advapi32\n");
+ return LIBUSB_ERROR_OTHER;
+ }
+
+ pOpenSCManagerA = (POPENSCMANAGERA)GetProcAddress(h, "OpenSCManagerA");
+ if (pOpenSCManagerA == NULL) {
+ usbi_warn(ctx, "failed to find %s in Advapi32\n", "OpenSCManagerA");
+ goto error_free_library;
+ }
+ pOpenServiceA = (POPENSERVICEA)GetProcAddress(h, "OpenServiceA");
+ if (pOpenServiceA == NULL) {
+ usbi_warn(ctx, "failed to find %s in Advapi32\n", "OpenServiceA");
+ goto error_free_library;
+ }
+ pCloseServiceHandle = (PCLOSESERVICEHANDLE)GetProcAddress(h, "CloseServiceHandle");
+ if (pCloseServiceHandle == NULL) {
+ usbi_warn(ctx, "failed to find %s in Advapi32\n", "CloseServiceHandle");
+ goto error_free_library;
+ }
- managerHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
+ managerHandle = pOpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
if (managerHandle == NULL) {
usbi_warn(ctx, "failed to open service control manager: %s", windows_error_str(0));
- return LIBUSB_ERROR_OTHER;
+ goto error_free_library;
}
- serviceHandle = OpenServiceA(managerHandle, "UsbDk", GENERIC_READ);
- CloseServiceHandle(managerHandle);
+ serviceHandle = pOpenServiceA(managerHandle, "UsbDk", GENERIC_READ);
+ pCloseServiceHandle(managerHandle);
if (serviceHandle == NULL) {
if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST)
usbi_warn(ctx, "failed to open UsbDk service: %s", windows_error_str(0));
+ FreeLibrary(h);
return LIBUSB_ERROR_NOT_FOUND;
}
- CloseServiceHandle(serviceHandle);
+ pCloseServiceHandle(serviceHandle);
+ FreeLibrary(h);
return load_usbdk_helper_dll(ctx);
+
+error_free_library:
+ FreeLibrary(h);
+ return LIBUSB_ERROR_OTHER;
}
static void usbdk_exit(struct libusb_context *ctx)