How to get normal DLL method name

Denis Mezhov d.o.mezhov at gmail.com
Sat Feb 15 23:20:03 PST 2014


On Sunday, 16 February 2014 at 07:17:48 UTC, Denis Mezhov wrote:
> Don't work
>
> DLL
>
> module dllmain;
>
> import std.c.windows.windows;
> import core.sys.windows.dll;
> import core.stdc.stdio;
>
> __gshared HINSTANCE g_hInst;
>
> export void dllprint()
> {
> 	printf("hello dll world\n");	
> }
>
> extern (Windows)
> BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID 
> pvReserved)
> {
>     final switch (ulReason)
>     {
>     case DLL_PROCESS_ATTACH:
>         g_hInst = hInstance;
>         dll_process_attach( hInstance, true );
>         break;
>
>     case DLL_PROCESS_DETACH:
>         dll_process_detach( hInstance, true );
>         break;
>
>     case DLL_THREAD_ATTACH:
>         dll_thread_attach( true, true );
>         break;
>
>     case DLL_THREAD_DETACH:
>         dll_thread_detach( true, true );
>         break;
>     }
>     return true;
> }
>
>
>
>
> Main
>
> import core.runtime;
>
> import std.stdio;
> import std.container;
> import std.range;
> import std.c.windows.windows;
>
> alias void function() aaa;
> aaa bbb;
>
> extern (Windows)
> void main(string[] args)
> {
>    HMODULE h;
>    FARPROC fp;	
>    h = cast(HMODULE) Runtime.loadLibrary("DynamicLib1.dll");	
>    if (h is null)
>       {
>          printf("error loading mydll.dll\n");
>       }
>    fp = GetProcAddress(h, "dllprint");  //Don't work
>       if (fp is null)
>       {
>           printf("error loading symbol()\n");
>       }
>
>   bbb = cast(aaa)fp;
>   bbb();
>
>   readln();
> }

Oh, sorry

export extern (C) void dllprint()
{
    printf("hello dll world\n");	
}

It work


More information about the Digitalmars-d-learn mailing list