Solved

Delphi and DLLs

Posted on 2001-07-22
4
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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