?
Solved

Using C-written DLLs in Delphi

Posted on 2003-03-13
5
Medium Priority
?
243 Views
Last Modified: 2010-04-04
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
Comment
Question by:csg9001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Accepted Solution

by:
mocarts earned 300 total points
ID: 8128686
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
 
LVL 3

Expert Comment

by:sfock
ID: 8129513
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
 
LVL 17

Expert Comment

by:geobul
ID: 8129917
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
 
LVL 3

Expert Comment

by:sfock
ID: 8130124
if you declareate stdcall in C you must use cdekl in delphi. refer the help to go sure the declarations fit together
0
 

Author Comment

by:csg9001
ID: 8131886
Thanks,
The compiler did indeed mangle the name of my function. This dependency-walker is great!

Regards,
Jan Hendrik Boelens
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question