home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IPROCADR.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
8KB
|
163 lines
#ifndef _IPROCADR_
#define _IPROCADR_
/*******************************************************************************
* FILE NAME: iprocadr.hpp *
* *
* DESCRIPTION: *
* This file contains the declaration(s) of the class(es): *
* IProcedureAddress - Dynamic link library entry point. *
* *
* COPYRIGHT: *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or *
* disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _IBASE_
#include <ibase.hpp>
#endif
#ifndef _IRESLIB_
#include <ireslib.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
template < class PtrToFnType >
class IProcedureAddress : public IBase {
typedef IBase
Inherited;
/*******************************************************************************
* The IProcedureAddress class provides a wrapper for OS/2 dynamic-link *
* library (DLL) entry points obtained using DosLoadModule or DosGetProcAddr. *
* (DosLoadModule is used to do a runtime link to a DLL. DosGetProcAddr is *
* used to acquire the runtime address of a function in a DLL. When used *
* together, they allow the calling of code that was not known to the linker *
* when the executable module was built.) *
* *
* This class provides for: *
* - Constructing instances from entry point names (or ordinal entry point *
* numbers) and DLL objects (or .dll names). *
* - Calling the entry point without having to deal with casting to and from *
* the generic "PFN" type supported by DosGetProcAddr. *
* - Managing (along with IDynamicLinkLibrary) the loading and freeing of *
* the associated DLL file. *
* *
* Customization (Template Arguments) *
* Class IProcedureAddress is a template class instantiated with the template *
* arguments: *
* class PtrToFnType - Type of the entry point to be loaded or called; this *
* must be a "pointer to function" type. *
* *
* Example: *
* *
* // "MyFnType" is pointer to function returning char *, ... *
* typedef char *(*MyFnType)( const char *, int, c ); *
* *
* // myFn is dynamic entry point to function "myFunction" in DLL "myDLL". *
* IProcedureAddress<MyFnType> myFn( "myFunction", "myDLL" ); *
* *
* // Call dynamically loaded entry point: *
* char *p = myFn( "argument 1", 2, '3' ); *
*******************************************************************************/
public:
/*------------------------- Constructors ---------------------------------------
Two pieces of information are needed to construct an object of this class:
- The entry point. This can be specified as either an entry point name
(const char *) or entry point ordinal (unsigned).
- The DLL from which the entry point is to be loaded. This can be
specified either as a reference to an existing IDynamicLinkLibrary
object or simply by the DLL name.
------------------------------------------------------------------------------*/
IProcedureAddress ( const char *entryPoint,
const char *dllName )
: dll( new IDynamicLinkLibrary( dllName ) ),
isOrdinal( false ),
name( entryPoint )
{
fnPtr = PtrToFnType( this->dll->procAddress( entryPoint ) );
}
IProcedureAddress ( const char *entryPoint,
IDynamicLinkLibrary &aDLL )
: dll( new IDynamicLinkLibrary( aDLL ) ),
isOrdinal( false ),
name( entryPoint )
{
fnPtr = PtrToFnType( this->dll->procAddress( entryPoint ) );
}
IProcedureAddress ( unsigned long ordinal,
const char *dllName )
: dll( new IDynamicLinkLibrary( dllName ) ),
isOrdinal( true ),
ord( ordinal )
{
fnPtr = PtrToFnType( this->dll->procAddress( ordinal ) );
}
IProcedureAddress ( unsigned long ordinal,
IDynamicLinkLibrary &aDLL )
: dll( new IDynamicLinkLibrary( aDLL ) ),
isOrdinal( true ),
ord( ordinal )
{
fnPtr = PtrToFnType( this->dll->procAddress( ordinal ) );
}
~IProcedureAddress ( )
{
delete dll;
}
/*-------------------------------- Accessing -----------------------------------
| The following functions provide means of getting an setting the accessible |
| attributes of instances of this class: |
| operator PtrToFnType - This operator is provided to permit instances of |
| this template class to be used in the same way as |
| pointers-to-functions, which is like regular |
| function names. |
| is32Bit - Returns whether the entry point is 32-bit. |
------------------------------------------------------------------------------*/
operator PtrToFnType ( ) const
{
return fnPtr;
}
Boolean
is32Bit ( ) const
{
if ( isOrdinal )
return dll->isEntryPoint32Bit( ord );
else
return dll->isEntryPoint32Bit( name );
}
private: /*------------------------ PRIVATE ----------------------------------*/
PtrToFnType
fnPtr;
IDynamicLinkLibrary
*dll;
Boolean
isOrdinal;
union
{
unsigned long
ord;
const char
*name;
};
}; // class IProcedureAddress
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#endif // _IPROCADR_