Re: Using DLL in Delphi



Bob Richardson wrote:
My friend is writing a DLL in C++ that I want to use in my Delphi
program . Are there any special pitfalls I need to worry about?
Perhaps something I can suggest he not do so that my implementation
will be smoother?

Here are some pieces of advice for him:

1. All exported functions should use the stdcall calling convention.

2. All exported functions should be declared using extern "C" so avoid exporting C++-mangled names. A side effect of this means he can't export overloaded functions.

3. To be thorough, he should use a DEF file to make sure that the exported functions have completely undecorated names. Otherwise, a function name will have a leading underscore and a trailing "@nn", where nn is the number of bytes occupied by parameters on the stack. This will occur even after following the advice in point 2 above. (Failure to follow point 3 just means you'll need to use a "name" clause when importing the function in Delphi.)

4. He should not bother exporting classes or variables. Delphi can't import anything but functions.

5. If he wants to export classes anyway, he should follow the instructions on the page below.

http://rvelthuis.de/articles/articles-cppobjs.html

6. Use the style of the Windows API for passing strings back and forth. That is, he should use the LPSTR type and a buffer size when returning strings, and LPCSTR for receiving strings.

--
Rob
.



Relevant Pages

  • VS 2003 COM Server and Delphi Client
    ... I have a COM Server I wrote according to a book I have in C#, ... can call the object fine from a VB Script, however, if I try to import the ... type library into Delphi 6 I get a "type not validated" error on Byte, ... It appears as though Delphi is just not seeing the exported functions for ...
    (microsoft.public.dotnet.languages.csharp)
  • ANN: Advanced guide to interop (.Net and COM) in Delphi is published
    ... .Net interop includes using registered for COM assembly, ... without registering .Net assembly for COM, using exported functions from ... .Net assembly written in Delphi .Net. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Writing a library (DLL or LIB)
    ... Delphi knows nothing about lib files because Delphi doesn't need them. ... Btw when declaring the exported functions in the DLL use the variable types ...
    (borland.public.delphi.thirdpartytools.general)