//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : DllExchange.cpp Data : 27.03.15 Versione : 1.6c9 // Contenuto : Funzioni di gestione della libreria opzionale EgtExchange. // // // // Modifiche : 27.03.15 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "DllExchange.h" #define NOMINMAX #include using namespace std ; //----------------------------------------------------------------------------- // Nome della libreria #if defined( _WIN64) && defined( _DEBUG) static const wchar_t* EEX_NAME = L"EgtExchangeD64.dll" ; #elif defined( _WIN64) static const wchar_t* EEX_NAME = L"EgtExchangeR64.dll" ; #elif defined( _WIN32) && defined( _DEBUG) static const wchar_t* EEX_NAME = L"EgtExchangeD32.dll" ; #else static const wchar_t* EEX_NAME = L"EgtExchangeR32.dll" ; #endif // Nome delle funzioni caricate static const char* EEX_SETEEXLOGGER = "SetEExLogger" ; static const char* EEX_GETEEXVERSION = "GetEExVersion" ; static const char* EEX_SETEEXKEY = "SetEExKey" ; static const char* EEX_CREATEIMPORTCSF = "CreateImportCsf" ; static const char* EEX_CREATEIMPORTCNC = "CreateImportCnc" ; static const char* EEX_CREATEIMPORTDXF = "CreateImportDxf" ; static const char* EEX_CREATEIMPORTSTL = "CreateImportStl" ; static const char* EEX_CREATEEXPORTDXF = "CreateExportDxf" ; static const char* EEX_CREATEEXPORTSTL = "CreateExportStl" ; static const char* EEX_CREATEEEXEXECUTOR = "CreateExcExecutor" ; //----------------------------------------------------------------------------- HMODULE s_hEEx = nullptr ; //----------------------------------------------------------------------------- bool LoadExchangeDll( void) { // se già caricata if ( s_hEEx != nullptr) return true ; // carico la libreria EgtExchange s_hEEx = LoadLibrary( EEX_NAME) ; return ( s_hEEx != nullptr) ; } //----------------------------------------------------------------------------- bool FreeExchangeDll( void) { // se non è già caricata if ( s_hEEx == nullptr) return true ; // libero la libreria EgtExchange FreeLibrary( s_hEEx) ; s_hEEx = nullptr ; return true ; } //----------------------------------------------------------------------------- bool IsLoadedExchangeDll( void) { return ( s_hEEx != nullptr) ; } //----------------------------------------------------------------------------- void MySetEExLogger( ILogger* pLogger) { // verifico caricamento libreria EgtExchange if ( s_hEEx == nullptr) return ; // recupero funzione che imposta il logger typedef void (* PF_SetEExLogger) ( ILogger* pLogger) ; PF_SetEExLogger pFun = (PF_SetEExLogger)GetProcAddress( s_hEEx, EEX_SETEEXLOGGER) ; if ( pFun == nullptr) return ; pFun( pLogger) ; } //----------------------------------------------------------------------------- const char* MyGetEExVersion( void) { // verifico caricamento libreria EgtExchange if ( s_hEEx == nullptr) return "" ; // recupero funzione che restituisce la versione della libreria typedef const char* (* PF_GetEExVersion) ( void) ; PF_GetEExVersion pFun = (PF_GetEExVersion)GetProcAddress( s_hEEx, EEX_GETEEXVERSION) ; if ( pFun == nullptr) return "" ; return pFun() ; } //----------------------------------------------------------------------------- void MySetEExKey( const string& sKey) { // verifico caricamento libreria EgtExchange if ( s_hEEx == nullptr) return ; // recupero funzione che imposta i codici di protezione typedef void (* PF_SetEExKey) ( const string& sKey) ; PF_SetEExKey pFun = (PF_SetEExKey)GetProcAddress( s_hEEx, EEX_SETEEXKEY) ; if ( pFun == nullptr) return ; pFun( sKey) ; } //----------------------------------------------------------------------------- IImportCsf* MyCreateImportCsf( void) { // verifico caricamento libreria EgtExchange if ( s_hEEx == nullptr) return nullptr ; // recupero funzione creazione oggetto typedef IImportCsf* (* PF_CreateImportCsf) ( void) ; PF_CreateImportCsf pFun = (PF_CreateImportCsf)GetProcAddress( s_hEEx, EEX_CREATEIMPORTCSF) ; if ( pFun == nullptr) return nullptr ; return pFun() ; } //----------------------------------------------------------------------------- IImportCnc* MyCreateImportCnc( void) { // verifico caricamento libreria EgtExchange if ( s_hEEx == nullptr) return nullptr ; // recupero funzione creazione oggetto typedef IImportCnc* (* PF_CreateImportCnc) ( void) ; PF_CreateImportCnc pFun = (PF_CreateImportCnc)GetProcAddress( s_hEEx, EEX_CREATEIMPORTCNC) ; if ( pFun == nullptr) return nullptr ; return pFun() ; } //----------------------------------------------------------------------------- IImportDxf* MyCreateImportDxf( void) { // verifico caricamento libreria EgtExchange if ( s_hEEx == nullptr) return nullptr ; // recupero funzione creazione oggetto typedef IImportDxf* (* PF_CreateImportDxf) ( void) ; PF_CreateImportDxf pFun = (PF_CreateImportDxf)GetProcAddress( s_hEEx, EEX_CREATEIMPORTDXF) ; if ( pFun == nullptr) return nullptr ; return pFun() ; } //----------------------------------------------------------------------------- IImportStl* MyCreateImportStl( void) { // verifico caricamento libreria EgtExchange if ( s_hEEx == nullptr) return nullptr ; // recupero funzione creazione oggetto typedef IImportStl* (* PF_CreateImportStl) ( void) ; PF_CreateImportStl pFun = (PF_CreateImportStl)GetProcAddress( s_hEEx, EEX_CREATEIMPORTSTL) ; if ( pFun == nullptr) return nullptr ; return pFun() ; } //----------------------------------------------------------------------------- IExportDxf* MyCreateExportDxf( void) { // verifico caricamento libreria EgtExchange if ( s_hEEx == nullptr) return nullptr ; // recupero funzione creazione oggetto typedef IExportDxf* (* PF_CreateExportDxf) ( void) ; PF_CreateExportDxf pFun = (PF_CreateExportDxf)GetProcAddress( s_hEEx, EEX_CREATEEXPORTDXF) ; if ( pFun == nullptr) return nullptr ; return pFun() ; } //----------------------------------------------------------------------------- IExportStl* MyCreateExportStl( void) { // verifico caricamento libreria EgtExchange if ( s_hEEx == nullptr) return nullptr ; // recupero funzione creazione oggetto typedef IExportStl* (* PF_CreateExportStl) ( void) ; PF_CreateExportStl pFun = (PF_CreateExportStl)GetProcAddress( s_hEEx, EEX_CREATEEXPORTSTL) ; if ( pFun == nullptr) return nullptr ; return pFun() ; } //----------------------------------------------------------------------------- IExcExecutor* MyCreateExcExecutor( void) { // verifico caricamento libreria EgtExchange if ( s_hEEx == nullptr) return nullptr ; // recupero funzione creazione oggetto typedef IExcExecutor* (* PF_CreateExcExecutor) ( void) ; PF_CreateExcExecutor pFun = (PF_CreateExcExecutor)GetProcAddress( s_hEEx, EEX_CREATEEEXEXECUTOR) ; if ( pFun == nullptr) return nullptr ; return pFun() ; }