Delphi调用VC编写的dll报错,一个很简单的小程序,请高手帮我看下。
我是在学习用Delphi调用VC编写的dll,
目前有一个小问题,总是报错,我把源程序贴出来,请高手帮我看下,谢谢!
VC编写的dll源代码:(dd.dll)
extern "C " __declspec(dllexport) void go(int &x, int &y);
void go(int &x, int &y)
{
int temp ;
temp = x + y;
}
Delphi部分:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure go(var a,b:integer);stdcall;
external 'dd.dll ';
procedure TForm1.Button1Click(Sender: TObject);
var x,y:integer;
begin
x:=20;
y:=21;
go(x,y);
end;
end.
这个程序我不是要达到什么功能,就是想学习一下Delphi调用VC编写的dll的方法。
我不知道为什么会出错,错误显示:
Access violation at address 00000014. Read of address 00000014.
附我的源程序下载:
http://www.qintian.name/qt.rar
谢谢大家了!
[解决办法]
extern "C " __declspec(dllexport) void go(int &x, int &y);
这两个参数是int指针吧
还有c里的dll输出的函数也加上个stdcall 吧
[解决办法]
dll没写好
[解决办法]
procedure go(x,y : PInteger);cdecl;
[解决办法]
如果没有指明调用方式,C语言函数默认的调用方式是cdecl
Delphi里得和dll里函数调用方式一致才行