Windows: Add windows_common.h header
authorToby Gray <toby.gray@realvnc.com>
Tue, 15 Jan 2013 22:36:47 +0000 (22:36 +0000)
committerToby Gray <toby.gray@realvnc.com>
Wed, 23 Jan 2013 00:39:49 +0000 (00:39 +0000)
* This file contains definition that will be shared between the
  Windows and Windows CE backends

14 files changed:
libusb/Makefile.am
libusb/os/windows_common.h [new file with mode: 0644]
libusb/os/windows_usb.h
libusb/version_nano.h
msvc/libusb_dll.dsp
msvc/libusb_dll_2005.vcproj
msvc/libusb_dll_2010.vcxproj
msvc/libusb_dll_2010.vcxproj.filters
msvc/libusb_static.dsp
msvc/libusb_static_2005.vcproj
msvc/libusb_static_2010.vcxproj
msvc/libusb_static_2010.vcxproj.filters
msvc/libusb_static_2012.vcxproj
msvc/libusb_static_2012.vcxproj.filters

index 53fba6e..d248e47 100644 (file)
@@ -50,7 +50,8 @@ libusb_1_0_la_LDFLAGS = $(LTLDFLAGS)
 libusb_1_0_la_SOURCES = libusbi.h core.c descriptor.c io.c sync.c $(OS_SRC) \
        os/linux_usbfs.h os/darwin_usb.h os/windows_usb.h \
        $(THREADS_SRC) \
-       os/poll_posix.h os/poll_windows.h
+       os/poll_posix.h os/poll_windows.h \
+       os/windows_common.h
 
 hdrdir = $(includedir)/libusb-1.0
 hdr_HEADERS = libusb.h
diff --git a/libusb/os/windows_common.h b/libusb/os/windows_common.h
new file mode 100644 (file)
index 0000000..d12be6b
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Windows backend common header for libusbx 1.0
+ *
+ * This file brings together header code common between
+ * the desktop Windows and Windows CE backends.
+ * Copyright © 2009-2012 Pete Batard <pete@akeo.ie>
+ * With contributions from Michael Plante, Orin Eman et al.
+ * Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
+ * Major code testing contribution by Xiaofan Chen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#pragma once
+
+// Windows API default is uppercase - ugh!
+#if !defined(bool)
+#define bool BOOL
+#endif
+#if !defined(true)
+#define true TRUE
+#endif
+#if !defined(false)
+#define false FALSE
+#endif
+
+#define safe_free(p) do {if (p != NULL) {free((void*)p); p = NULL;}} while(0)
+#define safe_closehandle(h) do {if (h != INVALID_HANDLE_VALUE) {CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0)
+#define safe_min(a, b) min((size_t)(a), (size_t)(b))
+#define safe_strcp(dst, dst_max, src, count) do {memcpy(dst, src, safe_min(count, dst_max)); \
+       ((char*)dst)[safe_min(count, dst_max)-1] = 0;} while(0)
+#define safe_strcpy(dst, dst_max, src) safe_strcp(dst, dst_max, src, safe_strlen(src)+1)
+#define safe_strncat(dst, dst_max, src, count) strncat(dst, src, safe_min(count, dst_max - safe_strlen(dst) - 1))
+#define safe_strcat(dst, dst_max, src) safe_strncat(dst, dst_max, src, safe_strlen(src)+1)
+#define safe_strcmp(str1, str2) strcmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2))
+#define safe_stricmp(str1, str2) _stricmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2))
+#define safe_strncmp(str1, str2, count) strncmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2), count)
+#define safe_strlen(str) ((str==NULL)?0:strlen(str))
+#define safe_sprintf _snprintf
+#define safe_stprintf _sntprintf
+#define safe_tcslen(str) ((str==NULL)?0:_tcslen(str))
+#define safe_unref_device(dev) do {if (dev != NULL) {libusb_unref_device(dev); dev = NULL;}} while(0)
+#define wchar_to_utf8_ms(wstr, str, strlen) WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, strlen, NULL, NULL)
+#ifndef ARRAYSIZE
+#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
+#endif
+
+#define ERR_BUFFER_SIZE             256
+#define TIMER_REQUEST_RETRY_MS      100
+#define MAX_TIMER_SEMAPHORES        128
+
+
+/*
+ * API macros - from libusb-win32 1.x
+ */
+#define DLL_DECLARE_PREFIXNAME(api, ret, prefixname, name, args)    \
+       typedef ret (api * __dll_##name##_t)args;                       \
+       static __dll_##name##_t prefixname = NULL
+
+#ifndef _WIN32_WCE
+#define DLL_STRINGIFY(dll) #dll
+#define DLL_GET_MODULE_HANDLE(dll) GetModuleHandleA(DLL_STRINGIFY(dll))
+#define DLL_LOAD_LIBRARY(dll) LoadLibraryA(DLL_STRINGIFY(dll))
+#else
+#define DLL_STRINGIFY(dll) L#dll
+#define DLL_GET_MODULE_HANDLE(dll) GetModuleHandle(DLL_STRINGIFY(dll))
+#define DLL_LOAD_LIBRARY(dll) LoadLibrary(DLL_STRINGIFY(dll))
+#endif
+
+#define DLL_LOAD_PREFIXNAME(dll, prefixname, name, ret_on_failure) \
+       do {                                                           \
+               HMODULE h = DLL_GET_MODULE_HANDLE(dll);                    \
+       if (!h)                                                        \
+               h = DLL_LOAD_LIBRARY(dll);                                 \
+       if (!h) {                                                      \
+               if (ret_on_failure) { return LIBUSB_ERROR_NOT_FOUND; }     \
+               else { break; }                                            \
+       }                                                              \
+       prefixname = (__dll_##name##_t)GetProcAddress(h,               \
+                               DLL_STRINGIFY(name));                  \
+       if (prefixname) break;                                         \
+       prefixname = (__dll_##name##_t)GetProcAddress(h,               \
+                               DLL_STRINGIFY(name) DLL_STRINGIFY(A)); \
+       if (prefixname) break;                                         \
+       prefixname = (__dll_##name##_t)GetProcAddress(h,               \
+                               DLL_STRINGIFY(name) DLL_STRINGIFY(W)); \
+       if (prefixname) break;                                         \
+       if(ret_on_failure)                                             \
+               return LIBUSB_ERROR_NOT_FOUND;                             \
+       } while(0)
+
+#define DLL_DECLARE(api, ret, name, args)   DLL_DECLARE_PREFIXNAME(api, ret, name, name, args)
+#define DLL_LOAD(dll, name, ret_on_failure) DLL_LOAD_PREFIXNAME(dll, name, name, ret_on_failure)
+#define DLL_DECLARE_PREFIXED(api, ret, prefix, name, args)   DLL_DECLARE_PREFIXNAME(api, ret, prefix##name, name, args)
+#define DLL_LOAD_PREFIXED(dll, prefix, name, ret_on_failure) DLL_LOAD_PREFIXNAME(dll, prefix##name, name, ret_on_failure)
+
index 8c5329b..5d67a56 100644 (file)
@@ -22,6 +22,8 @@
 
 #pragma once
 
+#include "windows_common.h"
+
 #if defined(_MSC_VER)
 // disable /W4 MSVC warnings that are benign
 #pragma warning(disable:4127) // conditional expression is constant
 #pragma warning(disable:4201) // nameless struct/union
 #endif
 
-// Windows API default is uppercase - ugh!
-#if !defined(bool)
-#define bool BOOL
-#endif
-#if !defined(true)
-#define true TRUE
-#endif
-#if !defined(false)
-#define false FALSE
-#endif
-
 // Missing from MSVC6 setupapi.h
 #if !defined(SPDRP_ADDRESS)
 #define SPDRP_ADDRESS  28
@@ -57,24 +48,6 @@ extern char *_strdup(const char *strSource);
 // _beginthreadex is MSVCRT => unavailable for cygwin. Fallback to using CreateThread
 #define _beginthreadex(a, b, c, d, e, f) CreateThread(a, b, (LPTHREAD_START_ROUTINE)c, d, e, f)
 #endif
-#define safe_free(p) do {if (p != NULL) {free((void*)p); p = NULL;}} while(0)
-#define safe_closehandle(h) do {if (h != INVALID_HANDLE_VALUE) {CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0)
-#define safe_min(a, b) min((size_t)(a), (size_t)(b))
-#define safe_strcp(dst, dst_max, src, count) do {memcpy(dst, src, safe_min(count, dst_max)); \
-       ((char*)dst)[safe_min(count, dst_max)-1] = 0;} while(0)
-#define safe_strcpy(dst, dst_max, src) safe_strcp(dst, dst_max, src, safe_strlen(src)+1)
-#define safe_strncat(dst, dst_max, src, count) strncat(dst, src, safe_min(count, dst_max - safe_strlen(dst) - 1))
-#define safe_strcat(dst, dst_max, src) safe_strncat(dst, dst_max, src, safe_strlen(src)+1)
-#define safe_strcmp(str1, str2) strcmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2))
-#define safe_stricmp(str1, str2) _stricmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2))
-#define safe_strncmp(str1, str2, count) strncmp(((str1==NULL)?"<NULL>":str1), ((str2==NULL)?"<NULL>":str2), count)
-#define safe_strlen(str) ((str==NULL)?0:strlen(str))
-#define safe_sprintf _snprintf
-#define safe_unref_device(dev) do {if (dev != NULL) {libusb_unref_device(dev); dev = NULL;}} while(0)
-#define wchar_to_utf8_ms(wstr, str, strlen) WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, strlen, NULL, NULL)
-#ifndef ARRAYSIZE
-#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
-#endif
 
 #define MAX_CTRL_BUFFER_LENGTH      4096
 #define MAX_USB_DEVICES             256
@@ -84,9 +57,6 @@ extern char *_strdup(const char *strSource);
 #define MAX_GUID_STRING_LENGTH      40
 #define MAX_PATH_LENGTH             128
 #define MAX_KEY_LENGTH              256
-#define MAX_TIMER_SEMAPHORES        128
-#define TIMER_REQUEST_RETRY_MS      100
-#define ERR_BUFFER_SIZE             256
 #define LIST_SEPARATOR              ';'
 #define HTAB_SIZE                   1021
 
@@ -332,37 +302,6 @@ struct driver_lookup {
        const char* designation;        // internal designation (for debug output)
 };
 
-/*
- * API macros - from libusb-win32 1.x
- */
-#define DLL_DECLARE_PREFIXNAME(api, ret, prefixname, name, args)    \
-       typedef ret (api * __dll_##name##_t)args;                       \
-       static __dll_##name##_t prefixname = NULL
-
-#define DLL_LOAD_PREFIXNAME(dll, prefixname, name, ret_on_failure) \
-       do {                                                           \
-               HMODULE h = GetModuleHandleA(#dll);                        \
-       if (!h)                                                        \
-               h = LoadLibraryA(#dll);                                    \
-       if (!h) {                                                      \
-               if (ret_on_failure) { return LIBUSB_ERROR_NOT_FOUND; }     \
-               else { break; }                                            \
-       }                                                              \
-       prefixname = (__dll_##name##_t)GetProcAddress(h, #name);       \
-       if (prefixname) break;                                         \
-       prefixname = (__dll_##name##_t)GetProcAddress(h, #name "A");   \
-       if (prefixname) break;                                         \
-       prefixname = (__dll_##name##_t)GetProcAddress(h, #name "W");   \
-       if (prefixname) break;                                         \
-       if(ret_on_failure)                                             \
-               return LIBUSB_ERROR_NOT_FOUND;                             \
-       } while(0)
-
-#define DLL_DECLARE(api, ret, name, args)   DLL_DECLARE_PREFIXNAME(api, ret, name, name, args)
-#define DLL_LOAD(dll, name, ret_on_failure) DLL_LOAD_PREFIXNAME(dll, name, name, ret_on_failure)
-#define DLL_DECLARE_PREFIXED(api, ret, prefix, name, args)   DLL_DECLARE_PREFIXNAME(api, ret, prefix##name, name, args)
-#define DLL_LOAD_PREFIXED(dll, prefix, name, ret_on_failure) DLL_LOAD_PREFIXNAME(dll, prefix##name, name, ret_on_failure)
-
 /* OLE32 dependency */
 DLL_DECLARE_PREFIXED(WINAPI, HRESULT, p, CLSIDFromString, (LPCOLESTR, LPCLSID));
 
index fec778d..71078a1 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10593
+#define LIBUSB_NANO 10594
index bad8d15..f2b15f0 100644 (file)
@@ -181,6 +181,10 @@ SOURCE=..\libusb\os\threads_windows.h
 
 SOURCE=..\libusb\os\windows_usb.h
 # End Source File
+# Begin Source File
+
+SOURCE=..\libusb\os\windows_common.h
+# End Source File
 # End Group
 # Begin Group "Resource Files"
 
index 0672695..976f664 100644 (file)
                        />
                </Configuration>
                <Configuration
-                       Name="Release|Win32"
+                       Name="Debug|x64"
                        OutputDirectory="..\$(PlatformName)\$(ConfigurationName)\dll"
                        IntermediateDirectory="..\$(PlatformName)\$(ConfigurationName)\dll\libusb-1.0"
                        ConfigurationType="2"
                        CharacterSet="1"
-                       WholeProgramOptimization="1"
                        >
                        <Tool
                                Name="VCPreBuildEventTool"
                        />
                        <Tool
                                Name="VCMIDLTool"
+                               TargetEnvironment="3"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
+                               Optimization="0"
                                AdditionalIncludeDirectories=".;..\libusb"
-                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS"
-                               RuntimeLibrary="2"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
                                Detect64BitPortabilityProblems="false"
                        <Tool
                                Name="VCLinkerTool"
                                OutputFile="$(OutDir)\libusb-1.0.dll"
-                               LinkIncremental="1"
+                               LinkIncremental="2"
                                ModuleDefinitionFile="..\libusb\libusb-1.0.def"
                                GenerateDebugInformation="true"
                                SubSystem="2"
-                               OptimizeReferences="2"
-                               EnableCOMDATFolding="2"
-                               TargetMachine="1"
+                               TargetMachine="17"
                        />
                        <Tool
                                Name="VCALinkTool"
                        />
                </Configuration>
                <Configuration
-                       Name="Debug|x64"
+                       Name="Release|Win32"
                        OutputDirectory="..\$(PlatformName)\$(ConfigurationName)\dll"
                        IntermediateDirectory="..\$(PlatformName)\$(ConfigurationName)\dll\libusb-1.0"
                        ConfigurationType="2"
                        CharacterSet="1"
+                       WholeProgramOptimization="1"
                        >
                        <Tool
                                Name="VCPreBuildEventTool"
                        />
                        <Tool
                                Name="VCMIDLTool"
-                               TargetEnvironment="3"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
-                               Optimization="0"
                                AdditionalIncludeDirectories=".;..\libusb"
-                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS"
-                               MinimalRebuild="true"
-                               BasicRuntimeChecks="3"
-                               RuntimeLibrary="3"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS"
+                               RuntimeLibrary="2"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
                                Detect64BitPortabilityProblems="false"
                        <Tool
                                Name="VCLinkerTool"
                                OutputFile="$(OutDir)\libusb-1.0.dll"
-                               LinkIncremental="2"
+                               LinkIncremental="1"
                                ModuleDefinitionFile="..\libusb\libusb-1.0.def"
                                GenerateDebugInformation="true"
                                SubSystem="2"
-                               TargetMachine="17"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
                        />
                        <Tool
                                Name="VCALinkTool"
                                >
                        </File>
                        <File
-                               RelativePath="..\libusb\libusb-1.0.def"
+                               RelativePath="..\libusb\os\poll_windows.c"
                                >
                        </File>
                        <File
                                RelativePath="..\libusb\os\threads_windows.c"
                                >
                        </File>
-
-                       <File
-                               RelativePath="..\libusb\os\poll_windows.c"
-                               >
-                       </File>
                        <File
                                RelativePath="..\libusb\os\windows_usb.c"
                                >
                                >
                        </File>
                        <File
-                               RelativePath="..\libusb\os\threads_windows.h"
+                               RelativePath="..\libusb\os\poll_windows.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\libusb\os\poll_windows.h"
+                               RelativePath="..\libusb\os\threads_windows.h"
                                >
                        </File>
                        <File
                                RelativePath="..\libusb\os\windows_usb.h"
                                >
                        </File>
+                       <File
+                               RelativePath="..\libusb\os\windows_common.h"
+                               >
+                       </File>
                </Filter>
                <Filter
                        Name="Resource Files"
                        UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
                        >
                        <File
+                               RelativePath="..\libusb\libusb-1.0.def"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\libusb\libusb-1.0.rc"
                                >
                        </File>
index f1881fe..707f458 100644 (file)
     <ClInclude Include="..\libusb\os\poll_windows.h" />
     <ClInclude Include="..\libusb\os\threads_windows.h" />
     <ClInclude Include="..\libusb\os\windows_usb.h" />
+    <ClInclude Include="..\libusb\os\windows_common.h" />
   </ItemGroup>
   <ItemGroup>
     <None Include="..\libusb\libusb-1.0.def" />
index 3dacb2c..575bc4f 100644 (file)
@@ -55,6 +55,9 @@
     <ClInclude Include="..\libusb\os\windows_usb.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\libusb\os\windows_common.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\libusb\libusb-1.0.def">
index b636691..afdbbed 100644 (file)
@@ -165,6 +165,10 @@ SOURCE=..\libusb\os\threads_windows.h
 
 SOURCE=..\libusb\os\windows_usb.h
 # End Source File
+# Begin Source File
+
+SOURCE=..\libusb\os\windows_common.h
+# End Source File
 # End Group
 # End Target
 # End Project
index e9ba31d..1d41004 100644 (file)
                                RelativePath="..\libusb\os\windows_usb.h"
                                >
                        </File>
+                       <File
+                               RelativePath="..\libusb\os\windows_common.h"
+                               >
+                       </File>
                </Filter>
        </Files>
        <Globals>
index 57254be..0c445a4 100644 (file)
     <ClInclude Include="..\libusb\os\poll_windows.h" />
     <ClInclude Include="..\libusb\os\threads_windows.h" />
     <ClInclude Include="..\libusb\os\windows_usb.h" />
+    <ClInclude Include="..\libusb\os\windows_common.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
index 8585fcf..39dc64e 100644 (file)
@@ -52,5 +52,8 @@
     <ClInclude Include="..\libusb\os\windows_usb.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\libusb\os\windows_common.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file
index 4323d04..a8a6bdc 100644 (file)
     <ClInclude Include="..\libusb\os\poll_windows.h" />
     <ClInclude Include="..\libusb\os\threads_windows.h" />
     <ClInclude Include="..\libusb\os\windows_usb.h" />
+    <ClInclude Include="..\libusb\os\windows_common.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
index 8585fcf..39dc64e 100644 (file)
@@ -52,5 +52,8 @@
     <ClInclude Include="..\libusb\os\windows_usb.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\libusb\os\windows_common.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file