Files
EgtExchange/EExDllMain.cpp
DarioS 8426092c6f EgtExchange 2.5e5 :
- migliorato controllo gestione chiave di rete.
2023-05-30 10:25:16 +02:00

151 lines
4.6 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : EExDllMain.cpp Data : 04.04.14 Versione : 1.5d1
// Contenuto : Inizializzazione della DLL.
//
//
//
// Modifiche : 04.04.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "DllMain.h"
#include "/EgtDev/Include/EExDllMain.h"
#include "/EgtDev/Include/EGnGetModuleVer.h"
#include "/EgtDev/Include/EGnGetKeyData.h"
#include "/EgtDev/Include/EgtTrace.h"
//--------------------------- Costanti ----------------------------------------
#if defined( _WIN64) && defined( _DEBUG)
const char* EEX_STR = "EgtExchangeD64.dll ver. " ;
#elif defined( _WIN64)
const char* EEX_STR = "EgtExchangeR64.dll ver. " ;
#elif defined( _WIN32) && defined( _DEBUG)
const char* EEX_STR = "EgtExchangeD32.dll ver. " ;
#else
const char* EEX_STR = "EgtExchangeR32.dll ver. " ;
#endif
const int STR_DIM = 40 ;
//-----------------------------------------------------------------------------
static HINSTANCE s_hModule = NULL ;
static char s_szEExNameVer[STR_DIM] ;
//-----------------------------------------------------------------------------
BOOL APIENTRY
DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
if ( dwReason == DLL_PROCESS_ATTACH) {
// Controllo commentato per problemi con VB.NET
//#if defined( NDEBUG)
// BOOL IsDbgPresent = FALSE ;
// CheckRemoteDebuggerPresent( GetCurrentProcess(), &IsDbgPresent) ;
// if ( IsDbgPresent)
// return 0 ;
//#endif
s_hModule = hModule ;
EGT_TRACE( "EgtExchange.dll Initializing!\n") ;
}
else if ( dwReason == DLL_PROCESS_DETACH) {
s_hModule = NULL ;
EGT_TRACE( "EgtExchange.dll Terminating!\n") ;
}
return 1 ;
}
//-----------------------------------------------------------------------------
const char*
GetEExVersion( void)
{
std::string sVer ;
GetModuleVersion( s_hModule, sVer) ;
sprintf_s( s_szEExNameVer, STR_DIM, "%s%s", EEX_STR, sVer.c_str()) ;
return s_szEExNameVer ;
}
//-----------------------------------------------------------------------------
static ILogger* s_pLogger = nullptr ;
//-----------------------------------------------------------------------------
void
SetEExLogger( ILogger* pLogger)
{
s_pLogger = pLogger ;
}
//-----------------------------------------------------------------------------
ILogger*
GetEExLogger( void)
{
return s_pLogger ;
}
//-----------------------------------------------------------------------------
static std::string s_sKey ;
static bool s_bNetHwKey = false ;
//-----------------------------------------------------------------------------
void
SetEExKey( const std::string& sKey)
{
s_sKey = sKey ;
}
//-----------------------------------------------------------------------------
void
SetEExNetHwKey( bool bNetHwKey)
{
s_bNetHwKey = bNetHwKey ;
}
//-----------------------------------------------------------------------------
const std::string&
GetEExKey( void)
{
return s_sKey ;
}
//-----------------------------------------------------------------------------
bool
GetEExNetHwKey( void)
{
return s_bNetHwKey ;
}
//-----------------------------------------------------------------------------
bool
VerifyKey( int nKeyOpt)
{
// Controllo della licenza
unsigned int nOpt1, nOpt2 ;
int nOptExpDays ;
int nRet = GetEGnKeyOptions( KEY_BASELIB_PROD, KEY_BASELIB_VER, KEY_BASELIB_LEV,
nOpt1, nOpt2, nOptExpDays) ;
if ( ! GetEExNetHwKey())
nRet = GetKeyOptions( GetEExKey(), KEY_BASELIB_PROD, KEY_BASELIB_VER, KEY_BASELIB_LEV,
nOpt1, nOpt2, nOptExpDays) ;
if ( nRet != KEY_OK && ! EqualNoCase( GetEExKey(), "EExBase")) {
if ( nRet != KEY_OK) {
std::string sErr = "Error on Key (EXC/" + ToString( nRet) + ")" ;
LOG_ERROR( GetEExLogger(), sErr.c_str()) ;
return false ;
}
if ( ( nOpt1 & ( KEYOPT_EEX_INPBASE|KEYOPT_EEX_EXPBASE)) == 0 ||
( nKeyOpt != 0 && ( nOpt1 & nKeyOpt) == 0) ||
nOptExpDays < GetCurrDay()) {
std::string sErr = "Warning on Key (EXC/OPT)" ;
LOG_ERROR( GetEExLogger(), sErr.c_str()) ;
return false ;
}
}
return true ;
}