using d dll/lib with msvc program

Rainer Schuetze r.sagitario at gmx.de
Sun May 13 23:16:38 PDT 2012



On 5/14/2012 5:44 AM, crashtua wrote:
> And how to load that dll? I have dll:
> module dllmain;
> import std.c.windows.windows;
> import core.sys.windows.dll;
> __gshared HINSTANCE g_hInst;
> 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;
> }
> extern (C) int trololo(){return 10;}

add an "export" to the function:
export extern (C) int trololo(){return 10;}

> Than try to load it:
> HINSTANCE LoadME;
> LoadME = LoadLibrary(L"C:\\Users\\CrashTUA\\Documents\\visual studio
> 2010\\Projects\\DynamicLib1\\DynamicLib1\\Release\\DynamicLib1.dll");
> func dllprintt;
> dllprintt = (func)GetProcAddress(LoadME,"trololo");

The C calling convention prepends an underscore to the function name:
dllprintt = (func)GetProcAddress(LoadME,"_trololo");

> int i = dllprintt();
> return 0;
> And it gives me acces violation...


More information about the Digitalmars-d mailing list