Import C++ DLL

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Fri May 18 11:15:39 PDT 2007


CrowBar wrote:
> 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.
> 
[snip]
> 
> The program compiles but does not execute, it returns "Error Access
> Violation", (it should display the number 42).
> 
> 
[snip]
>     fnMyDLL = cast(fnMyDLL_fp) GetProcAddress(h, "fnMyDLL");
> 
>     printf("value=%i\n", fnMyDLL());
[snip]

GetProcAddress is probably returning null, you forgot to check for that. 
It seems to think the function doesn't exist. The most likely cause is 
name mangling.

Try adding an underscore before the first character in the function 
name. (IIRC that's the mangling for C functions on Windows)

If that didn't work, make sure the function is either compiled as C code 
or marked 'extern "C"' (directly or in an 'extern "C" {}' block) if it's 
compiled as C++ code.


More information about the Digitalmars-d-learn mailing list