Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 542
  • Last Modified:

How to call C++Builder DLL in Delphi?

I've created a DLL that came from C++Builder code using the 'extern "C" __declspec(dllexport)' modifier to export the functions I want to be able to call.  It compiles okay and then when I try to run a test program in Delphi to call the functions, I get an "Entry Point Not Found" error.  More specifically it says "The procedure entry point <function name> could not be located in the dynamic link library <dll filename>".

I looked over my C++ code and I've seemed to have done everything right.  The only clue I have is from a Delphi book that tells me that I need to "translate the C++ import library to a Pascal equivalent inteface unit".  Am I on the right track?
0
uhoang
Asked:
uhoang
1 Solution
 
rwilson032697Commented:
You can make a unit like this:

unit DLLinterface;

interface

Procedure Fred(Arg : Integer);

implementation

Procedure Fred(Arg : Integer); external 'MyDLL.DLL' name 'Fred';

end.

This will automatically load the DLL (if it can find it!) and allow you to call procedure fred defined in it.

It sounds like you might have the case of the function name wrong - be sure it matches!

Cheers,

Raymond.
0
 
uhoangAuthor Commented:
Ok, I did that and I still get the same result.  Is it possible that there's something wrong in the DLL?  After I build the DLL in C++Builder and place it in a folder in a correct path, do I need to do anything else like register it or anything?
0
 
FMJMEECommented:
See the web page
http://www.drbob42.com/delphi/headconv.htm
hope it helps
0
 
rwilson032697Commented:
Can you post the declaration of the function in the DLL and in the import unit?

Cheers,

Raymond.
0
 
FelixinCommented:
Hi,

Rwilson is OK.


You have to make sure that the protocol to call the DLL is correct.

Search i Delphi help for:

Calling conventions

There you will see that a DLL can have different calling methods, like (extracted)

The table below summarizes calling conventions.

Directive      Parameter order      Clean-up      Passes parameters in registers?
register      Left-to-right      Routine      Yes
pascal      Left-to-right      Routine      No
cdecl      Right-to-left      Caller      No
stdcall      Right-to-left      Routine      No
safecall      Right-to-left      Routine      No

Take the correct one a put it in the header of the function like this

function MyFunction : MyResult; cdecl; external 'MyDLL.DLL' name 'MyFunction';

Best regards
0

Featured Post

Technology Partners: 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!

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