Solved

Delphi and DLLs

Posted on 2001-07-22
4
276 Views
Last Modified: 2010-04-06
I created a DLL and exported it using STDCALL.
Then, in the program i iported the function that i eported and when i tried to use it the program chrashed.

What could be the problem and how exactly do i write and use DLLs in Delphi...?

    Yevgeni...
0
Comment
Question by:Yevgen
  • 2
4 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 6306398
Did you import it using stdcall as well?
0
 

Author Comment

by:Yevgen
ID: 6306425
no i used: function funcname(i:integer):integer; export 'dllname.dll';
0
 
LVL 5

Accepted Solution

by:
scrapdog earned 100 total points
ID: 6306448
Make sure you import it the same way you export it.  If you *only* plan on using the DLL with Delphi apps, there is no need to declare it as stdcall.   Just declare it with the default calling convention (which happens to be 'register').  The default calling convention is faster than stdcall.

If you are exporting as stdcall, the function expects to access all of its parameters on the stack frame.  If you don't import as stdcall, Delphi thinks that this function is called with the register convention.  When it calls it, it puts some of its parameters in the CPU's registers, and the rest on the stack frame.

When calling conventions don't match, this will corrupt the parametrers, and most likely will cause the program to access memory at illegal locations.

If you want the DLL to potentially be used by other languages, declare the function as stdcall.  But also make sure you declare it as stdcall when you import it in Delphi.

0
 
LVL 21

Expert Comment

by:ziolko
ID: 6306633
If there will be only one parameter or none, function call probably will be made correctly. But generally it works like scrapdog said.
ziolko.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

829 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