11#include " stdafx.h"
22
3+ #include < string.h>
34#include " ../include/XApiC.h"
4- #include < libloaderapi.h>
55#include " ../include/QueueHeader.h"
66#include " ../include/QueueEnum.h"
77
8+ #if defined WINDOWS
9+ #include < libloaderapi.h>
10+ #else
11+ #include < dlfcn.h>
12+ #include < errno.h>
13+ #endif
14+
15+
816void * X_LoadLib (char * libPath)
917{
1018 if (libPath == nullptr )
1119 return nullptr ;
1220
21+ #if defined WINDOWS
1322 return LoadLibraryExA (libPath, nullptr , LOAD_WITH_ALTERED_SEARCH_PATH);
23+ #else
24+ return dlopen (libPath, RTLD_LAZY);
25+ #endif
1426}
1527
1628char * X_GetLastError ()
1729{
18- char szBuf[256 ] = {0 };
30+ #if defined WINDOWS
31+ char szBuf[256 ] = {0 };
1932 LPVOID lpMsgBuf;
2033 DWORD dw = GetLastError ();
2134 FormatMessageA (
@@ -25,32 +38,44 @@ char* X_GetLastError()
2538 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
2639 (LPSTR)&lpMsgBuf,
2740 0 , NULL );
28-
29- return (char *)lpMsgBuf;
41+ return (char *)lpMsgBuf;
42+ #else
43+ extern int errno;
44+ return strerror (errno);
45+ #endif
3046}
3147
3248void * X_GetFunction (void * lib)
3349{
3450 if (lib == nullptr )
3551 return nullptr ;
36-
37- return (fnOnRespone)GetProcAddress ((HMODULE)lib, " XRequest" );;
52+ #if defined WINDOWS
53+ return (fnOnRespone)GetProcAddress ((HMODULE)lib, " XRequest" );
54+ #else
55+ return static_cast <fnOnRespone*>(dlsym (lib, " XRequest" ));
56+ #endif
3857}
3958
4059void X_FreeLib (void * lib)
4160{
4261 if (lib == nullptr )
4362 return ;
4463
64+ #if defined WINDOWS
4565 FreeLibrary ((HMODULE)lib);
66+ #else
67+ dlclose (lib);
68+ #endif
4669}
4770
4871ApiType X_GetApiType (void * pFun)
4972{
5073 if (pFun == nullptr )
5174 return ApiType::Nono;
5275
53- return (ApiType)(char )((fnOnRespone)pFun)(RequestType::GetApiType, nullptr , nullptr , 0 , 0 , nullptr , 0 , nullptr , 0 , nullptr , 0 );
76+ void * p = ((fnOnRespone)pFun)(RequestType::GetApiType, nullptr , nullptr , 0 , 0 , nullptr , 0 , nullptr , 0 , nullptr , 0 );
77+
78+ return (ApiType)(char )(long long )(p);
5479}
5580
5681char * X_GetApiVersion (void * pFun)
@@ -187,4 +212,4 @@ void X_CancelQuote(void* pFun, void* pApi, OrderIDType* pIn, OrderIDType* pOut,
187212 return ;
188213
189214 ((fnOnRespone)pFun)(RequestType::ReqQuoteAction, pApi, nullptr , 0 , 0 , pIn, count, pOut, 0 , nullptr , 0 );
190- }
215+ }
0 commit comments