| 1 |
|
| 2 |
// Copyright (c) 2003-2019 Xsens Technologies B.V. or subsidiaries worldwide. |
| 3 |
// All rights reserved. |
| 4 |
// |
| 5 |
// Redistribution and use in source and binary forms, with or without modification, |
| 6 |
// are permitted provided that the following conditions are met: |
| 7 |
// |
| 8 |
// 1. Redistributions of source code must retain the above copyright notice, |
| 9 |
// this list of conditions, and the following disclaimer. |
| 10 |
// |
| 11 |
// 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 |
// this list of conditions, and the following disclaimer in the documentation |
| 13 |
// and/or other materials provided with the distribution. |
| 14 |
// |
| 15 |
// 3. Neither the names of the copyright holders nor the names of their contributors |
| 16 |
// may be used to endorse or promote products derived from this software without |
| 17 |
// specific prior written permission. |
| 18 |
// |
| 19 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 20 |
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 |
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 22 |
// THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 |
// SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
| 24 |
// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 |
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR |
| 26 |
// TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 |
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS |
| 28 |
// SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES |
| 29 |
// OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE |
| 30 |
// ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES. |
| 31 |
// |
| 32 |
|
| 33 |
#ifdef _WIN32 |
| 34 |
# ifndef WINVER // Allow use of features specific to Windows XP or later. |
| 35 |
# define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows. |
| 36 |
# endif |
| 37 |
|
| 38 |
# ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. |
| 39 |
# define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. |
| 40 |
# endif |
| 41 |
|
| 42 |
# ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. |
| 43 |
# define _WIN32_WINDOWS 0x0501 // Change this to the appropriate value to target Windows Me or later. |
| 44 |
# endif |
| 45 |
|
| 46 |
# ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later. |
| 47 |
# define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE. |
| 48 |
# endif |
| 49 |
# ifndef WIN32_LEAN_AND_MEAN |
| 50 |
# define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers |
| 51 |
# endif |
| 52 |
# include <windows.h> |
| 53 |
#else |
| 54 |
#endif |
| 55 |
#include "xstypesdynlib.h" |
| 56 |
#include "xstime.h" |
| 57 |
#include "xsstring.h" |
| 58 |
|
| 59 |
#ifdef _MANAGED |
| 60 |
#pragma managed(push, off) |
| 61 |
#endif |
| 62 |
|
| 63 |
// The so_* functions are also used by programs that use xstypes as a static library |
| 64 |
// When the function contents change, check if this functionality is also required in these programs |
| 65 |
void |
| 66 |
#ifdef __GNUC__ |
| 67 |
__attribute__((constructor(65535))) |
| 68 |
#endif |
| 69 |
so_init(void) |
| 70 |
{ |
| 71 |
XsTime_initializeTime(); |
| 72 |
} |
| 73 |
|
| 74 |
void |
| 75 |
#ifdef __GNUC__ |
| 76 |
__attribute__((destructor)) |
| 77 |
#endif |
| 78 |
so_fini(void) |
| 79 |
{ |
| 80 |
} |
| 81 |
|
| 82 |
#ifdef _WIN32 |
| 83 |
HMODULE g_hModule = 0; |
| 84 |
BOOL APIENTRY DllMain( HMODULE hModule, |
| 85 |
DWORD ul_reason_for_call, |
| 86 |
LPVOID lpvReserved |
| 87 |
) |
| 88 |
{ |
| 89 |
g_hModule = hModule; |
| 90 |
|
| 91 |
switch (ul_reason_for_call) |
| 92 |
{ |
| 93 |
case DLL_PROCESS_ATTACH: |
| 94 |
so_init(); |
| 95 |
break; |
| 96 |
case DLL_THREAD_ATTACH: |
| 97 |
break; |
| 98 |
case DLL_THREAD_DETACH: |
| 99 |
break; |
| 100 |
case DLL_PROCESS_DETACH: |
| 101 |
// The lpvReserved parameter to DllMain is NULL if the DLL is being unloaded because of a call to FreeLibrary, it's non NULL if the DLL is being unloaded due to process termination. |
| 102 |
// in case of process termination, all the threads have already been destroyed and we'll just assume that windows will clean us up |
| 103 |
if (lpvReserved == NULL) |
| 104 |
so_fini(); |
| 105 |
break; |
| 106 |
default: |
| 107 |
break; |
| 108 |
} |
| 109 |
return TRUE; |
| 110 |
} |
| 111 |
#endif |
| 112 |
|
| 113 |
/*! \brief Return the path that the xsensdeviceapi.dll file is currently running from |
| 114 |
\param path Storage for the path |
| 115 |
\note This is a windows-only function |
| 116 |
*/ |
| 117 |
XSTYPES_DLL_API void xstypesPath(XsString* path) |
| 118 |
{ |
| 119 |
#ifdef XSENS_WINDOWS |
| 120 |
wchar_t filename[1024] = L""; |
| 121 |
if (!path) |
| 122 |
return; |
| 123 |
|
| 124 |
if (!GetModuleFileNameW(g_hModule, filename, 1024)) |
| 125 |
XsString_destruct(path); |
| 126 |
else |
| 127 |
XsString_assignWCharArray(path, filename); |
| 128 |
#else |
| 129 |
if (!path) |
| 130 |
return; |
| 131 |
XsString_destruct(path); |
| 132 |
#endif |
| 133 |
} |
| 134 |
#ifdef _MANAGED |
| 135 |
#pragma managed(pop) |
| 136 |
#endif |