Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cOSModule Class Reference

#include <cOSModule.h>

Inheritance diagram for Gray::cOSModule:
GrayLib::cOSModuleX

Public Member Functions

 cOSModule (HMODULE hModule=((HMODULE) nullptr), UINT32 uFlags=k_Load_Normal)
 
 cOSModule (const FILECHAR_t *pszModuleName, UINT32 uFlags)
 
 ~cOSModule ()
 
FARPROC GetSymbolAddress (const char *pszSymbolName) const
 
bool isValidModule () const noexcept
 
 operator HMODULE () const noexcept
 
HMODULE get_ModuleHandle () const noexcept
 
UINT_PTR get_ModuleInt () const noexcept
 
bool isResourceModule () const noexcept
 
StrLen_t GetModulePath (FILECHAR_t *pszModuleName, StrLen_t nSizeMax) const
 
cStringF get_Name () const
 
HRESULT GetLastErrorDef (HRESULT hResDef=E_FAIL) const
 
void AttachModule (HMODULE hModule=((HMODULE) nullptr), UINT32 uFlags=k_Load_Normal)
 
void ClearModule () noexcept
 
HMODULE DetachModule () noexcept
 
void FreeThisModule ()
 
bool AttachModuleName (const FILECHAR_t *pszModuleName, UINT32 uFlags=k_Load_NoRefCount)
 
HRESULT LoadModule (const FILECHAR_t *pszModuleName, UINT32 uFlags=k_Load_Normal)
 
HRESULT LoadModuleWithSymbol (const FILECHAR_t *pszModuleName, const char *pszSymbolName)
 

Static Public Member Functions

static MIME_TYPE __stdcall CheckModuleTypeFile (const FILECHAR_t *pszPathName)
 
static HMODULE __stdcall GetModuleHandleForAddr (const void *pAddr)
 

Static Public Attributes

static const UINT k_Load_OSMask = 0x0FFFFFFF
 
static const UINT k_Load_ByName = 0x40000000
 try to find it (by just its file name, NOT Path) already loaded first. NOT OS flag. More...
 
static const UINT k_Load_NoRefCount = 0x80000000
 I DO NOT own the ref count. Don't free. NOT OS Flag. More...
 

Protected Member Functions

void FreeModuleLast ()
 

Friends

class cOSModuleTests
 

Detailed Description

manage access to a dynamically loaded *.DLL file. (or .SO in linux) in _WIN32 HMODULE is just a load address. Not the same as cOSHandle? ASSUME Default = loaded into my app space ! Use cOSModuleX for other processes modules. Inside a DLL there may be procedures and resources. DLL's are "shared objects" or "shared libraries" in linux linux link with "dl" library other times use 1. static binding or 2. delayed binding to DLL

Todo:
Get module footprint info. how much memory does it use?

Constructor & Destructor Documentation

◆ cOSModule() [1/2]

Gray::cOSModule::cOSModule ( HMODULE  hModule = ((HMODULE)nullptr),
UINT32  uFlags = k_Load_Normal 
)

◆ cOSModule() [2/2]

Gray::cOSModule::cOSModule ( const FILECHAR_t pszModuleName,
UINT32  uFlags 
)

◆ ~cOSModule()

Gray::cOSModule::~cOSModule ( )

Member Function Documentation

◆ AttachModule()

void Gray::cOSModule::AttachModule ( HMODULE  hModule = ((HMODULE)nullptr),
UINT32  uFlags = k_Load_Normal 
)
inline

◆ AttachModuleName()

bool Gray::cOSModule::AttachModuleName ( const FILECHAR_t pszModuleName,
UINT32  uFlags = k_Load_NoRefCount 
)

is the DLL/SO already loaded? Find it by name. Full Path is NOT necessary

◆ CheckModuleTypeFile()

MIME_TYPE GRAYCALL Gray::cOSModule::CheckModuleTypeFile ( const FILECHAR_t pszPathName)
static

Does this file appear to be a module/PE type ?

Returns
0 = MIME_UNKNOWN, 3=MIME_EXE, 2=MIME_DLL.
Todo:
linux must check the MIME type on the actual file.

◆ ClearModule()

void Gray::cOSModule::ClearModule ( )
inlinenoexcept

◆ DetachModule()

HMODULE Gray::cOSModule::DetachModule ( )
inlinenoexcept

◆ FreeModuleLast()

void Gray::cOSModule::FreeModuleLast ( )
protected

Assume someone else will clear m_hModule

Note
if this is the last ref to the DLL then it will be unloaded!
If we free a DLL that has vtable stuff in it, any objects based on these vtables are now broken!

◆ FreeThisModule()

void Gray::cOSModule::FreeThisModule ( )
Note
don't call this 'FreeModule' since that can be overloaded by _WIN32 "#define".

◆ get_ModuleHandle()

HMODULE Gray::cOSModule::get_ModuleHandle ( ) const
inlinenoexcept

◆ get_ModuleInt()

UINT_PTR Gray::cOSModule::get_ModuleInt ( ) const
inlinenoexcept

Get the modules handle as an int.

◆ get_Name()

cStringF Gray::cOSModule::get_Name ( ) const
Returns
Full path to the module.

◆ GetLastErrorDef()

HRESULT Gray::cOSModule::GetLastErrorDef ( HRESULT  hResDef = E_FAIL) const
inline

◆ GetModuleHandleForAddr()

HMODULE GRAYCALL Gray::cOSModule::GetModuleHandleForAddr ( const void *  pAddr)
static

Return the handle for the module this pAddr is in. Do NOT increment ref count.

  • pAddr = a function pointer for the function we are called from. This code may be part of a shared object or DLL. track its handle in case it is unloaded dynamically.
    Returns
    cAppState::get_HModule() = just part of the current EXE HMODULE_NULL = error;

◆ GetModulePath()

StrLen_t Gray::cOSModule::GetModulePath ( FILECHAR_t pszModuleName,
StrLen_t  nSizeMax 
) const

Get the file path to the loaded module.

Note
there is not absolute rule that it must have one.

◆ GetSymbolAddress()

FARPROC Gray::cOSModule::GetSymbolAddress ( const char *  pszSymbolName) const

Get a Generic function call address in the module. assume nothing about the functions args.

Note
No such thing as a UNICODE proc/function/symbol name! object formats existed before UNICODE. except for UNDER_CE which does support UNICODE proc names !?
this does not work if loaded using LOAD_LIBRARY_AS_IMAGE_RESOURCE or LOAD_LIBRARY_AS_DATAFILE

◆ isResourceModule()

bool Gray::cOSModule::isResourceModule ( ) const
inlinenoexcept

◆ isValidModule()

bool Gray::cOSModule::isValidModule ( ) const
inlinenoexcept

◆ LoadModule()

HRESULT Gray::cOSModule::LoadModule ( const FILECHAR_t pszModuleName,
UINT32  uFlags = k_Load_Normal 
)
  • uFlags = k_Load_ByName = find if its already loaded first. full path isn't important. LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_AS_IMAGE_RESOURCE
    Note
    We should use cAppStateModuleLoad with this.

◆ LoadModuleWithSymbol()

HRESULT Gray::cOSModule::LoadModuleWithSymbol ( const FILECHAR_t pszModuleName,
const char *  pszSymbolName 
)

Load this module ONLY if it exposes this symbol.

Returns
HRESULT_WIN32_C(ERROR_CALL_NOT_IMPLEMENTED) = I don't have this symbol

◆ operator HMODULE()

Gray::cOSModule::operator HMODULE ( ) const
inlinenoexcept

Friends And Related Function Documentation

◆ cOSModuleTests

friend class cOSModuleTests
friend

Member Data Documentation

◆ k_Load_ByName

const UINT Gray::cOSModule::k_Load_ByName = 0x40000000
static

try to find it (by just its file name, NOT Path) already loaded first. NOT OS flag.

◆ k_Load_NoRefCount

const UINT Gray::cOSModule::k_Load_NoRefCount = 0x80000000
static

I DO NOT own the ref count. Don't free. NOT OS Flag.

◆ k_Load_OSMask

const UINT Gray::cOSModule::k_Load_OSMask = 0x0FFFFFFF
static

The documentation for this class was generated from the following files: