PDA

View Full Version : Using Delphi DLL on C++



Relfos
18-06-2012, 10:44 AM
I have a DLL writtten in Delphi that I want to use in a C++ program. It seems that in C++ you always need a .lib file (at least in Visual Studio), and I generated that from the .dll file.
But still, it gives linker errors (it seems to be trying to import the functions as import_functionname instead of just functioname).
Anyone here has experience of mixing C++ with Delphi?
I could use LoadLibrary and load everything manually, but that's around 400 functions :(

Ñuño Martínez
18-06-2012, 12:10 PM
I could use LoadLibrary and load everything manually, but that's around 400 functions :( You'll need to declare them anyway. ::)

There are a lot of time I didn't use DLL from C, but I remember it depends a lot from the compiler you're using. GCC, Borland C and Visual have different ways to define the "external" function. IIRC the simplest was GCC, just adding "extern" as a prefix:


extern pascal int myfoofunction (int param);

Remember that you need the "pascal" word too (some compilers define a "PASCAL" macro too) and that names are lower-case.

Andru
18-06-2012, 01:09 PM
It seems that in C++ you always need a .lib
This file is needed only for Visual C++ and Borland C++ as I remember. GCC can use dll without it(but maybe I'm wrong and there was somewhere *.a file around my dll, which I linked with project long time ago :)). So the only way is using LoadLibrary and getting addresses of functions directly.

Relfos
18-06-2012, 03:27 PM
I see, it seems that using LoadLibrary is the way to go then. I'll try to find a way to auto generate the bindings instead of having to write everything by hand :)