X-Git-Url: https://harrygodden.com/git/?p=csRadar.git;a=blobdiff_plain;f=csrPlatform.h;fp=csrPlatform.h;h=46f65133d41062b6cecc1d0d2a007669a5df33a6;hp=0000000000000000000000000000000000000000;hb=8382aed7f0cdc38bc5c58832d4a15277cf56d4be;hpb=0bd8697a99ced50789a5d41b84a4b87f39cb1653 diff --git a/csrPlatform.h b/csrPlatform.h new file mode 100644 index 0000000..46f6513 --- /dev/null +++ b/csrPlatform.h @@ -0,0 +1,66 @@ +// Copyright (C) 2021 Harry Godden (hgn) + +// Cross platform (windows/unix) dynamic linking wrapper +//======================================================================================================================= + +#ifdef CSR_EXECUTABLE + +#if defined(_WIN32) || defined(__CYGWIN__) + #define CSR_WINDOWS + #include + typedef HWMODULE csr_so; +#else + #define CSR_UNIX + #include + typedef void *csr_so; +#endif + +csr_so csr_libopen( const char *name ) +{ + char path[ 512 ]; + strcpy( path, "ext/" ); + strcat( path, name ); + + #ifdef CSR_UNIX + strcat( path, ".so" ); + #else + strcat( path, ".dll" ); + #endif + + log_info( "Loading dynamic library (%s)\n", path ); + + #ifdef CSR_UNIX + return dlopen( path, RTLD_NOW ); + #else + return LoadLibrary( path ); + #endif +} + +void *csr_get_proc( csr_so so, const char *name ) +{ + #ifdef CSR_UNIX + return dlsym( so, name ); + #else + return (void *)GetProcAddress( so, name ); + #endif +} + +void csr_libclose( csr_so so ) +{ + #ifdef CSR_UNIX + dlclose( so ); + #else + FreeLibrary( so ); + #endif +} + +void csr_liberr(void) +{ + #ifdef CSR_UNIX + log_error( "Could not load that DLL (%s)\n", dlerror() ); + #else + log_error( "Could not load that DLL (Windows unkown)\n" ); + #endif +} + +#endif