An Aurora style wrapper for DLLs:
import unsigned int LoadLibrary alias "LoadLibraryA" ( string libname );
import unsigned int GetProcAddress( unsigned int lib, string procname );
import int FreeLibrary( unsigned int handle );
class CLibrary
{
/*private*/ unsigned int handle;
declare _CLibrary( );
declare IsValid( ),int;
declare Load( string path ),int;
declare Free( );
declare GetSub( string name ),unsigned int;
}
CLibrary::_CLibrary( )
{
Free( );
}
CLibrary::IsValid( )
{
return this->handle != 0;
}
CLibrary::Load( string path )
{
if( this->handle ) FreeLibrary( this->handle );
this->handle = LoadLibrary( path );
return this->handle != 0;
}
CLibrary::Free( )
{
if( this->handle ) FreeLibrary( this->handle );
}
CLibrary::GetSub( string name )
{
if( this->handle ) return GetProcAddress( this->handle, name );
return 0;
}
Example usage:
CLibrary lib;
declare *MyFunction( int x );
if( lib.Load( GetStartPath( ) + "mydll.dll" ) )
{
MyFunction = lib.GetSub( "MyFunction" );
if( MyFunction ) MyFunction( 1 );
}
// Library automatically freed