|
MKoD - D Programming Language
Console Program that uses the WinDLL.dll - code-name Main_Loader.d
Console Executable that calls WinDLL.dll with "D's" loader:
/+******************************************************
* Program : Main_Loader.exe
* Source : Main_Loader.d
* Author : David L. 'SpottedTiger' Davis
* Created Date : 13.Jun.04 Compiled and Tested with dmd v0.93
* Modified Date : 08.Jul.04 Compiled and Tested with dmd v0.95
* : 22.Jul.04 Compiled and Tested with dmd v0.96
* : 22.Dec.04 Corrected mistakes in code and then
* : Compiled and Tested with dmd v0.109
* : 28.Feb.05 Compiled and Tested with dmd v0.114
* : 06.Jun.06 Compiled and Tested with dmd v0.160
* : 10.Jan.07 Compiled and Tested with dmd v1.0
* :
* Requirements : std.loader, std.string, and std.stdio
* :
* License : Public Domain
*******************************************************************
* Note: This is an example of using the std.loader to pull in a Win32
* DLL into memory, and then using the free functions within it.
*
* Example of using WinDLL.dll's imported functions
* To Compiled: C:\dmd\MKoD_ex>dmd Main_Loader.d
+/
private import std.loader;
private import std.stdio;
private import std.string;
// set up pointers to the free functions - default parameter work fine!
typedef bool ( *pfn_isroman )( in dchar );
typedef bool ( *pfn_isromanstr )( in char[] );
int main ( in char[][] args )
{
HXModule hLibWinDLL = null;
char[] sLibName = "";
char[] sPath = "";
sPath = args[0][ 0 .. std.string.rfind( args[ 0 ], r"\" ) ].dup;
sLibName = sPath ~ r"\WinDLL.dll";
// Load DLL
hLibWinDLL = ExeModule_Load( sLibName );
writefln("\"%s\" is loaded, hLibWinDLL=%X", sLibName, cast(int)hLibWinDLL );
pfn_isroman isroman = cast(pfn_isroman)ExeModule_GetSymbol( hLibWinDLL, "isroman" );
pfn_isromanstr isromanstr = cast(pfn_isromanstr)ExeModule_GetSymbol( hLibWinDLL, "isromanstr" );
//Currently it appears the char / dchar aren't pass correctly,
//so the answer is always wrong. I need to check into this more.
//---------------------------------------------------------------
//writefln( "Testing isroman(\'%s\') = %b", 'C', isroman( 'C' ) );
writefln( "Testing isromanstr(\"%s\") = %b", "MMVC", isromanstr( "MMVC" ) );
writefln( "Testing isromanstr( \"%s\" ) = %b", "ABCDEF", isromanstr( "ABCDEF" ) );
// Unload DLL
ExeModule_Release( hLibWinDLL );
return 0;
} // end int main( in char[][] )
Compile main_loader.d
C:\dmd\MKOD_ex>..\bin\dmd main_loader.d
C:\dmd\bin\..\..\dm\bin\link.exe main_loader,,,user32+kernel32/noi;
C:\dmd\MKOD_ex>main_loader
"C:\dmd\MKOD_ex\WinDLL.dll" is loaded, hLibWinDLL=10000000
Testing isromanstr("MMVC") = 1
Testing isromanstr( "ABCDEF" ) = 0
C:\dmd\MKOD_ex>
|