 |
Source Code of "ParaPortDll.h"
/*
///////////////////////////////////////////////////////////////////////////////
//
// class ParaPortDll
//
// copyright (c) 2002, 2003, 2004 by Paul R. ADAM
// all rights reserved
// read the "http://www.ParaPort.net/TermsOfUse.html"
//
// more information on "http://www.ParaPort.net"
//
///////////////////////////////////////////////////////////////////////////////
*/
#ifndef ParaPortDll_h
#define ParaPortDll_h
#include
#include "ParaPort.h"
#pragma pack( 1 )
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
///////////////////////////////////////////////////////////////////////////////
// interface compatible with v1.3
BOOL closePort( HANDLE Handle );
BOOL executeCycle( HANDLE Handle, PARAPORT_CYCLE* ParaPortCycle, int Count );
HANDLE openPort( const char* PortName );
///////////////////////////////////////////////////////////////////////////////
// new interface v2.0
PARAPORT_ADDRESS __stdcall getPortAddress( const char* PortName );
UCHAR __stdcall input( PARAPORT_ADDRESS Address );
UCHAR __stdcall output( PARAPORT_ADDRESS Address, UCHAR Byte );
#ifdef __cplusplus
}
#endif /* __cplusplus */
///////////////////////////////////////////////////////////////////////////////
// interface compatible with v1.3
typedef BOOL ( *ParaPort_closePort ) ( HANDLE Handle );
typedef BOOL ( *ParaPort_executeCycle ) ( HANDLE Handle, PARAPORT_CYCLE* ParaPortCycle, int Count );
typedef HANDLE ( *ParaPort_openPort ) ( const char* PortName );
///////////////////////////////////////////////////////////////////////////////
// new interface v2.0
typedef PARAPORT_ADDRESS ( __stdcall *ParaPort_getPortAddress ) ( const char* PortName );
typedef UCHAR ( __stdcall *ParaPort_input ) ( PARAPORT_ADDRESS Address );
typedef UCHAR ( __stdcall *ParaPort_output ) ( PARAPORT_ADDRESS Address, UCHAR Byte );
#ifdef __cplusplus
///////////////////////////////////////////////////////////////////////////////
class ParaPortDll
{
///////////////////////////////////////////////////////////////////////////////
// interface compatible with v1.3:
public:
BOOL closePort( HANDLE Handle )
{
if ( !_closePort )
{
::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
return FALSE;
}
return _closePort( Handle );
}
static void deleteSingleton( ) { initSingleton( true ); }
BOOL executeCycle( HANDLE Handle, PARAPORT_CYCLE* Cycle, int Count = 1 )
{
if ( !_executeCycle )
{
::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
return FALSE;
}
return _executeCycle( Handle, Cycle, Count );
}
static ParaPortDll* getSingleton( ) { return initSingleton( false ); }
BOOL loadLibrary( const char* FileName )
{
_Instance = ::LoadLibrary( FileName );
if ( !_Instance )
return FALSE;
_closePort = ( ParaPort_closePort ) ::GetProcAddress( _Instance, "closePort" );
_executeCycle = ( ParaPort_executeCycle ) ::GetProcAddress( _Instance, "executeCycle" );
_openPort = ( ParaPort_openPort ) ::GetProcAddress( _Instance, "openPort" );
_getPortAddress = ( ParaPort_getPortAddress ) ::GetProcAddress( _Instance, "getPortAddress" );
_input = ( ParaPort_input ) ::GetProcAddress( _Instance, "input" );
_output = ( ParaPort_output ) ::GetProcAddress( _Instance, "output" );
return TRUE;
}
HANDLE openPort( const char* PortName )
{
if ( !_openPort )
{
::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
return INVALID_HANDLE_VALUE;
}
return _openPort( PortName );
}
///////////////////////////////////////////////////////////////////////////////
// new interface v2.0:
public:
PARAPORT_ADDRESS getPortAddress( const char* PortName )
{
if ( !_getPortAddress )
{
::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
return NULL;
}
return _getPortAddress( PortName );
}
UCHAR input( PARAPORT_ADDRESS Address )
{
if ( !_input )
{
::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
return 0x00;
}
return _input( Address );
}
UCHAR output( PARAPORT_ADDRESS Address, UCHAR Byte )
{
if ( !_output)
{
::SetLastError( PARAPORT_ERROR_LIBRARY_NOT_LOADED );
return 0x00;
}
return _output( Address, Byte );
}
///////////////////////////////////////////////////////////////////////////////
// implementation:
protected:
// constructor
ParaPortDll( ) : _Instance( NULL )
, _closePort( NULL )
, _executeCycle( NULL )
, _openPort( NULL )
, _getPortAddress( NULL )
, _input( NULL )
, _output( NULL )
{ }
~ParaPortDll( ) {
if ( _Instance )
::FreeLibrary( _Instance );
}
static ParaPortDll* initSingleton( bool Delete )
{
static ParaPortDll* Singleton = NULL;
if ( Delete )
{
if ( Singleton )
{
delete Singleton;
Singleton = NULL;
}
}
else
{
if ( !Singleton )
Singleton = new ParaPortDll;
}
return Singleton;
}
HMODULE _Instance;
ParaPort_closePort _closePort;
ParaPort_executeCycle _executeCycle;
ParaPort_openPort _openPort;
ParaPort_getPortAddress _getPortAddress;
ParaPort_input _input;
ParaPort_output _output;
};
#endif /* __cplusplus */
#pragma pack( )
#endif /* ParaPortDll_h */
/*
///////////////////////////////////////////////////////////////////////////////
*/
Copyright (c) 2002, 2003, 2004 by Paul R. ADAM,
v2.0, read the Terms of Use
|
 |