[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Using DLL calls

Posted on 2000-03-23
6
Medium Priority
?
174 Views
Last Modified: 2010-04-04
I had created a dll with the MFC Wizard (Project of the type Win32 Dynamic-Link Library). This dll had just one function call in it as shown below.

extern "C"
__declspec (dllexport) __int32  pipt_teste( __int32 *pt )
{
      *pt = 50;
      return 0;
}


And then I tried to use it in my delphi program.

In the mainframe I created a menu option called 'Test', and then when this option was called it create a form dynamically with a button in it. When the button was activated, it call the pipt_teste. The code is shown below:


function pipt_teste( pTeste : Pointer ) : Integer; stdcall; external 'prjDLL.dll'

....

procedure TFrm.BtOkClick(Sender: TObject);
var
   teste : Integer;
begin

   if pipt_teste( @teste ) then
      modalResult := mrOk
   else
      modalResult := mrAbort;

end;


What happening was, after calling the pipt_teste function, something was lost, the modalResult was not available more, the same happened to all attributes within the class.

What is wrong with my code?

Thanks for the help.
0
Comment
Question by:mauling
[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
6 Comments
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2650600
You are using the wrong calling convention. Try

function pipt_teste( pTeste : Pointer ) : Integer; cdecl; external 'prjDLL.dll'

0
 
LVL 15

Expert Comment

by:simonet
ID: 2651396
Try this:

function pipt_teste(var pTeste : longint ) : Integer; stdcall; external 'prjDLL.dll'

It cannot be CDECL, because it's declared as STDCALL in the DLL.

Yours,

Alex
0
 

Accepted Solution

by:
zealsoft earned 300 total points
ID: 2651517
The declrarion of MFC DLL is not correct. If you use __declspec (dllexport) to declare a function, VC will use decorated names, so you can't call it correctly in Delphi.You need to change as follows,

1. Change your C function:
extern "C"
__stdcall __int32  pipt_teste( __int32 *pt )
{
*pt = 50;
return 0;
}

2. Createa prjDLL.def file and add it to your VC project.
In the .def file:
      EXPORTS
         pipt_teste        

3. Change your Delphi declation
function pipt_teste(var pTeste : integer ) : Integer; stdcall; external 'prjDLL.dll'

4. When you call the function, you can use
 if pipt_teste( teste ) then
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Expert Comment

by:rwilson032697
ID: 2651643
Listening
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2651979
Where does anyone see STDCALL as the calling convention in the original question's DLL code? The answer is, was and will always be the calling convention.change it in the DLL or change it in the Delphi app, but change it.

0
 
LVL 1

Expert Comment

by:yk030299
ID: 2659384
listen
0

Featured Post

Technology Partners: 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…
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…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

650 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