Solved

Delphi and DLLs

Posted on 2001-07-22
4
271 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now