aa17b2b080
- modifiche per prima gestione chiave di rete.
165 lines
5.1 KiB
C++
165 lines
5.1 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2015-2015
|
|
//----------------------------------------------------------------------------
|
|
// File : DllMachKernel.cpp Data : 27.03.15 Versione : 1.6c9
|
|
// Contenuto : Funzioni di gestione della libreria opzionale EgtMachKernel.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 27.03.15 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "EXE.h"
|
|
#include "DllMachKernel.h"
|
|
#include "/EgtDev/Include/EMkDllMain.h"
|
|
#define NOMINMAX
|
|
#include <windows.h>
|
|
|
|
using namespace std ;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Nome della libreria
|
|
#if defined( _WIN64) && defined( _DEBUG)
|
|
static const wchar_t* EMK_NAME = L"EgtMachKernelD64.dll" ;
|
|
#elif defined( _WIN64)
|
|
static const wchar_t* EMK_NAME = L"EgtMachKernelR64.dll" ;
|
|
#elif defined( _WIN32) && defined( _DEBUG)
|
|
static const wchar_t* EMK_NAME = L"EgtMachKernelD32.dll" ;
|
|
#else
|
|
static const wchar_t* EMK_NAME = L"EgtMachKernelR32.dll" ;
|
|
#endif
|
|
// Nome delle funzioni caricate
|
|
static const char* EMK_SETEMKLOGGER = "SetEMkLogger" ;
|
|
static const char* EMK_GETEMKVERSION = "GetEMkVersion" ;
|
|
static const char* EMK_SETEMKKEY = "SetEMkKey" ;
|
|
static const char* EMK_SETEMKNETHWKEY = "SetEMkNetHwKey" ;
|
|
static const char* EMK_CREATEMACHMGR = "CreateMachMgr" ;
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
HMODULE s_hEMk = nullptr ;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
LoadMachKernelDll( ILogger* pLogger, const string& sKey, bool bNetHwKey)
|
|
{
|
|
// verifico la chiave
|
|
if ( ! TestKeyForEMk( sKey, 0, pLogger)) {
|
|
FreeMachKernelDll() ;
|
|
return false ;
|
|
}
|
|
// se già caricata
|
|
if ( s_hEMk != nullptr)
|
|
return true ;
|
|
// carico la libreria EgtMachKernel
|
|
s_hEMk = LoadLibrary( EMK_NAME) ;
|
|
if ( s_hEMk == nullptr)
|
|
return false ;
|
|
// imposto logger
|
|
MySetEMkLogger( pLogger) ;
|
|
// imposto i codici della chiave
|
|
MySetEMkKey( sKey) ;
|
|
// imposto eventuale chiave di rete
|
|
MySetEMkNetHwKey( bNetHwKey) ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
FreeMachKernelDll( void)
|
|
{
|
|
// se non è già caricata
|
|
if ( s_hEMk == nullptr)
|
|
return true ;
|
|
// libero la libreria EgtMachKernel
|
|
FreeLibrary( s_hEMk) ;
|
|
s_hEMk = nullptr ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
IsLoadedMachKernelDll( void)
|
|
{
|
|
return ( s_hEMk != nullptr) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void
|
|
MySetEMkLogger( ILogger* pLogger)
|
|
{
|
|
// verifico caricamento libreria MachMgr
|
|
if ( s_hEMk == nullptr)
|
|
return ;
|
|
// recupero funzione che imposta il logger
|
|
typedef void (* PF_SetEMkLogger) ( ILogger* pLogger) ;
|
|
PF_SetEMkLogger pFun = (PF_SetEMkLogger)GetProcAddress( s_hEMk, EMK_SETEMKLOGGER) ;
|
|
if ( pFun == nullptr)
|
|
return ;
|
|
pFun( pLogger) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
const char*
|
|
MyGetEMkVersion( void)
|
|
{
|
|
// verifico caricamento libreria MachMgr
|
|
if ( s_hEMk == nullptr)
|
|
return "" ;
|
|
// recupero funzione che restituisce la versione della libreria
|
|
typedef const char* (* PF_GetEMkVersion) ( void) ;
|
|
PF_GetEMkVersion pFun = (PF_GetEMkVersion)GetProcAddress( s_hEMk, EMK_GETEMKVERSION) ;
|
|
if ( pFun == nullptr)
|
|
return "" ;
|
|
return pFun() ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void
|
|
MySetEMkKey( const string& sKey)
|
|
{
|
|
// verifico caricamento libreria MachMgr
|
|
if ( s_hEMk == nullptr)
|
|
return ;
|
|
// recupero funzione che imposta i codici di protezione
|
|
typedef void (* PF_SetEMkKey) ( const string& sKey) ;
|
|
PF_SetEMkKey pFun = (PF_SetEMkKey)GetProcAddress( s_hEMk, EMK_SETEMKKEY) ;
|
|
if ( pFun == nullptr)
|
|
return ;
|
|
pFun( sKey) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void
|
|
MySetEMkNetHwKey( bool bNetHwKey)
|
|
{
|
|
// verifico caricamento libreria EgtGraphics
|
|
if ( s_hEMk == nullptr)
|
|
return ;
|
|
// recupero funzione che imposta il flag per chiave di rete
|
|
typedef void (* PF_SetEMkNetHwKey) ( bool bNetHwKey) ;
|
|
PF_SetEMkNetHwKey pFun = (PF_SetEMkNetHwKey)GetProcAddress( s_hEMk, EMK_SETEMKNETHWKEY) ;
|
|
if ( pFun == nullptr)
|
|
return ;
|
|
pFun( bNetHwKey) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
IMachMgr*
|
|
MyCreateMachMgr( void)
|
|
{
|
|
// verifico caricamento libreria MachMgr
|
|
if ( s_hEMk == nullptr)
|
|
return nullptr ;
|
|
// recupero funzione creazione oggetto
|
|
typedef IMachMgr* (* PF_CreateMachMgr) ( void) ;
|
|
PF_CreateMachMgr pFun = (PF_CreateMachMgr)GetProcAddress( s_hEMk, EMK_CREATEMACHMGR) ;
|
|
if ( pFun == nullptr)
|
|
return nullptr ;
|
|
return pFun() ;
|
|
}
|