Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi and DLLs

Posted on 2001-07-22
4
Medium Priority
?
284 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 400 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

722 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