build for windows
[csRadar.git] / csrPlatform.h
1 // Copyright (C) 2021 Harry Godden (hgn)
2
3 // Cross platform (windows/unix) dynamic linking wrapper
4 //=======================================================================================================================
5
6 #ifdef CSR_EXECUTABLE
7
8 #if defined(_WIN32) || defined(__CYGWIN__)
9 #define CSR_WINDOWS
10 #include <windows.h>
11 typedef HINSTANCE csr_so;
12 #else
13 #define CSR_UNIX
14 #include <dlfcn.h>
15 typedef void *csr_so;
16 #endif
17
18 csr_so csr_libopen( const char *name )
19 {
20 char path[ 512 ];
21 strcpy( path, "ext/" );
22 strcat( path, name );
23
24 #ifdef CSR_UNIX
25 strcat( path, ".so" );
26 #else
27 strcat( path, ".dll" );
28 #endif
29
30 log_info( "Loading dynamic library (%s)\n", path );
31
32 #ifdef CSR_UNIX
33 return dlopen( path, RTLD_NOW );
34 #else
35 return LoadLibrary( path );
36 #endif
37 }
38
39 void *csr_get_proc( csr_so so, const char *name )
40 {
41 #ifdef CSR_UNIX
42 return dlsym( so, name );
43 #else
44 return (void *)GetProcAddress( so, name );
45 #endif
46 }
47
48 void csr_libclose( csr_so so )
49 {
50 #ifdef CSR_UNIX
51 dlclose( so );
52 #else
53 FreeLibrary( so );
54 #endif
55 }
56
57 void csr_liberr(void)
58 {
59 #ifdef CSR_UNIX
60 log_error( "Could not load that DLL (%s)\n", dlerror() );
61 #else
62 log_error( "Could not load that DLL (Windows unkown)\n" );
63 #endif
64 }
65
66 #endif