Interfacing C++ to D --> or better: C++ --> C ---> D (DLL)

BeschBesch d475502 at drdrb.com
Sat Mar 29 08:03:15 PDT 2014


I want to use a set of functions that rely on a library which is 
not available for D (Harfbuzz). So I just wrote myself a set a 
functions that will do anything I need (Init, Free, Fonts, Text, 
etc).

The DLL is working fine and dynamically linking should work (it 
does in C++ --> LoadLibrary). Unfortunately, i get Error 42 
evertime i try to call a function.

As i suspected that some things written by me could be 
responsible for this, I build a test application with three 
functions (Test, Test2,Test3), got myself the D-.lib for 
statical-linking (implib-Dmd) and tried that one out. The result: 
Error 42.

What did I miss that can still cause linker errors? So far I did:

DLL is written in C (C89 --> VC++ only can afford that one it 
seems). And yes I changed it to C from C++ in the compiler 
settings.

DLL has an entry function AND a module-definition file (.def). A 
.lib-file is created alongside with the DLL (.def specified in 
porject settings). OF COURSE, I built a D-conform .lib by using 
implib with /s option (and without) /s option.

Thank you, if you are still reading.

CODE:
////// declared in Test.h
void Test1(void);
int Test2(int i);
long Test3(int* ptr);
////// Example implementation in Test.c (include "test.h"
void Test1(void)
{
	printf("FUNCTION WAS CALLED\n");
}
///// .def-File
LIBRARY "CtoDtestDll"
EXPORTS
Test1 @1
Test2 @2
Test3 @3
/// SETTINGS (C++)
Calling-convention: __cdecl (= std. ??)
Compiling for:   C (/TC)
/// SETTINGS (LINKER)
Modul-definition-file: CTestDll.def....

////// D-Module for usage with .lib from .dll (implib! from bup)
module CoreFuncs; // just a name

pragma (lib,"CtoDtestDll.lib"); // statically linking (could user 
settings too)

extern (C)   /// needed so the compiler can link the functions
{

void Test();

}


More information about the Digitalmars-d-learn mailing list