Solved

Delphi and DLLs

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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