• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Using C-written DLLs in Delphi

I have been trying to use DLL's that I wrote in C in my Delphi-programs, but I cannot get it to work.
The DLL compiles just fine, the Delphi-application loads the DLL, but I cannot access any functions inside the DLL from within my Delphi-program.

In the C-DLL I define the function as follows:

__declspec(dllexport) pascal void myFunc();

In my Delphi-program I import the function as foloows:

type
 TMyFunc = procedure(); {no parameters for simplicity}
var
 myFunc : TMyFunc ;
...
...
 myFunc := GetProcAddress(DLL_Handle,'myFunc'); {The DLL was previously loaded of course}
...

The only problem is, that after this myFunc contains NIL, and even after trying several linker-/compiler-settings it will not work.

I hope someone will be kind enough to help me on my way.

Many Thanks!

Jan Hendrik Boelens


0
csg9001
Asked:
csg9001
1 Solution
 
mocartsCommented:
maybe your C compiler mangles function name? can be _myFunc - take a look in your compiled dll (with some viewer or with dependency walker (can be downloaded at http://www.dependencywalker.com/))

wbr, mo.
0
 
sfockCommented:
try to link the function static like this

procedure myFunc external 'myDLL.dll'; pascal;

you might take a look at the onlinehelp for the proper callconvention (cdecl, pascal stdcall etc.)

0
 
geobulCommented:
Hi,

Try this also:

type
TMyFunc = procedure(); pascal;

But it's better if you are using stdcall convention (in the dll and the Delphi app), I think. Then it should be:

type
TMyFunc = procedure(); stdcall;

Regards, Geo
0
 
sfockCommented:
if you declareate stdcall in C you must use cdekl in delphi. refer the help to go sure the declarations fit together
0
 
csg9001Author Commented:
Thanks,
The compiler did indeed mangle the name of my function. This dependency-walker is great!

Regards,
Jan Hendrik Boelens
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now