April 27, 2024, 08:11:16 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


CLibrary

Started by Parker, August 26, 2006, 07:18:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Parker

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