Re: Using DLL in Delphi
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Fri, 24 Feb 2006 17:08:37 -0600
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
.
- References:
- Using DLL in Delphi
- From: Bob Richardson
- Using DLL in Delphi
- Prev by Date: Re: Using DLL in Delphi
- Next by Date: Re: BDS2006 exe sizes
- Previous by thread: Re: Using DLL in Delphi
- Next by thread: Re: Using DLL in Delphi
- Index(es):
Relevant Pages
|