Home > Back-end >  Delphi7 call C DLL suggest AV errors
Delphi7 call C DLL suggest AV errors

Time:11-03

 unit Unit1; 

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

Type
TForm1=class (TForm)
For: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Procedure Button1Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

The function to the Add (a: Integer; B: Integer) : Integer; Stdcall; External 'Dll1. DLL';

Var
Form1: TForm1;

Implementation

{$R *. DFM}

Procedure TForm1. Button1Click (Sender: TObject);
The begin
Edit1. Text:=IntToStr (Add (3, 6));//this is why the failure?

//Edit3. Text:=IntToStr (Add (StrToInt (Edit1. Text), StrToInt (Edit2. Text)));//this success
end;

End.


The code above
Is the simple addition, don't know why the first kind of writing is wrong, the second will have no matter son, bosses, please explain, thanks

//PCH. H: is this the precompiled header files, 
//the files listed below are compiled only once, and improve the performance of the future generation to generate,
//this will also affect the performance of IntelliSense, including code completion and many browsing,
//but if any of the files listed here in the generated between the update, all of them will be recompiled,
//do not add to frequently updated files here, this will enable performance advantage is invalid,

# # ifndef PCH_H
# define PCH_H

Extern "C" _declspec (dllexport) int the Add (int a, int b);
Extern "C" _declspec (dllexport) int Sub (int a, int b);

//add to precompiled header here
# include "framework. H"

# endif//PCH_H



//PCH. CPP: with the precompiled header corresponding source file 

# include "PCH. H"

//when using precompiled header, you need to use the source files, compiling to succeed,
Int the Add (int a, int b)
{
return a + b;
}

Int Sub (int a, int b)
{
Return a - b;
}

CodePudding user response:

Know why, the c + + default cdecl calling way, keyword cdecl in Delphi call also use to call
The function to the Add (a: Integer; B: Integer) : Integer; Cdecl; External 'Dll1. DLL';

Or changing the c + + to stdcall calling way line

Reference:
https://www.cnblogs.com/jiftle/p/8451336.html
https://blog.csdn.net/sss_369/article/details/87473329

CodePudding user response:

Top you ~

CodePudding user response:


So,
  • Related