Import C++ DLL

CrowBar john_owen at eml.cc
Fri May 18 07:37:40 PDT 2007


Please bear with me, I'm very new to C/C++ & D.

I want to Import a function from a DLL made with VC++ express edition into
D.

I have searched the Dprogramming webpages and put together the below code.

The program compiles but does not execute, it returns "Error Access
Violation", (it should display the number 42).


module ModMyDLL;
import std.c.stdio;
import std.c.windows.windows;
import std.stdio;
import std.gc;

//pragma (lib,"MyDLL.lib");

extern(C) alias int function() fnMyDLL_fp;

int main(char[][] args)
{
    HMODULE h;
    h = LoadLibraryA("MyDLL.dll");

    fnMyDLL_fp fnMyDLL;

    fnMyDLL = cast(fnMyDLL_fp) GetProcAddress(h, "fnMyDLL");

    printf("value=%i\n", fnMyDLL());

    return 0;
}




More information about the Digitalmars-d-learn mailing list