执行end出错,大侠帮忙!(100分)

  • 主题发起人 herbert1234
  • 开始时间
H

herbert1234

Unregistered / Unconfirmed
GUEST, unregistred user!
我用vc写了一个dll,在delphi中调用,如下:
implementation

function Min1(x,y,z:integer):integer;stdcall;external 'maxmin.dll';
function Max1(x,y,z:integer):integer;
stdcall;external 'maxmin.dll';

{$R *.dfm}

procedure TForm1.ToolButton1Click(Sender: TObject);
var a,b:integer;
begin

a:=Max1(2,3,4);
b:=a;
end;


程序在执行到最后以行end时 出现了一个Access violation错误,请高手帮帮忙!
 
vc中函数的定义是怎么样的?
 
把函数都改成这个试试
function Min1(x,y,z:integer):integer;stdcall;external 'maxmin.dll' name 'Min1';
 
定义了function,那你的具体function呢?
procedure TForm1.function (XXXXX) //应该是这个样子吧??
var a,b:integer;
begin

a:=Max1(2,3,4);
b:=a;
end;
 
function Min1(x,y,z:integer):integer;stdcall;external 'maxmin.dll';
function Max1(x,y,z:integer):integer;
stdcall;external 'maxmin.dll';
这两个函数定义应该放在{$R *.dfm}下面。具体为:

implementation
{$R *.dfm}

function Min1(x,y,z:integer):integer;stdcall;external 'maxmin.dll';
function Max1(x,y,z:integer):integer;
stdcall;external 'maxmin.dll';

procedure TForm1.ToolButton1Click(Sender: TObject);
var a,b:integer;
begin

a:=Max1(2,3,4);
b:=a;
end;


end;

//最后这个end;
是整个页面的结束符
 
按楼上几位大大的意见改了,还是不行, 掉用了dll的那个函数在end时就出错
以下是vc代码:
#include "stdafx.h"
#include "MaDll.h"
extern "C" __declspec(dllexport) int Min1(int x,int y,int z)
{
if ((x<=y) &amp;
(x<=z)) return x;

else
if ((y<=x) &amp;
(y<=z)) return y;

else
return z;
/*找出x,y,z中的最小整数*/
}

extern "C" __declspec(dllexport) int Max1(int x,int y,int z)
{
if ((x>=y) &amp;
(x>=z)) return x;

else
if ((y>=x) &amp;
(y>=z)) return y;

else
return z;
/*找出x,y,z中的最大整数*/
}

声明:
extern "C" _declspec(dllexport) int Min1(int x,int y,int z);

extern "C" _declspec(dllexport) int Max1(int x,int y,int z);
 
如果这样用就没错,各位大大帮忙分析下


implementation
function Min1(x,y,z:integer):integer;stdcall;external 'maxmin.dll';
function Max1(x,y,z:integer):integer;
stdcall;external 'maxmin.dll';


{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);

begin


edtMax.Text:=IntToStr(Max1(StrToInt(edtInt1.Text),StrToInt(edtInt2.Text),StrToInt(edtInt3.Text)));
//调用动态链接库中的函数Max1
edtMin.Text:=IntToStr(Min1(StrToInt(edtInt1.Text),StrToInt(edtInt2.Text),StrToInt(edtInt3.Text)));
//调用动态链接库中的函数Min1
end;


end.
 
把上面的执行部分改成这样:
procedure TForm1.Button1Click(Sender: TObject);
begin

edtMax.Text:=IntToStr(Max1(4,2,3));
edtMin.Text:=IntToStr(Min1(StrToInt(edtInt1.Text),StrToInt(edtInt2.Text),StrToInt(edtInt3.Text)));
//调用动态链接库中的函数Min1
end;

或者这样
procedure TForm1.Button1Click(Sender: TObject);

begin

edtMax.Text:=IntToStr(Max1(StrToInt(edtInt1.Text),StrToInt(edtInt2.Text),StrToInt(edtInt3.Text)));
//调用动态链接库中的函数Max1
edtMin.Text:=IntToStr(Min1(1,2,3));
end;


都没错

但是
改称这样
procedure TForm1.Button1Click(Sender: TObject);

begin

edtMax.Text:=IntToStr(Max1(4,2,3));
edtMin.Text:=IntToStr(Min1(1,2,3));
end;

就错了
大家帮帮我呀,,都要崩溃了!
 
你可以试一下,
1.
extern "C" __stdcall(dllexport) int Max1(int x,int y,int z)
声明:
extern "C" _stdcall(dllexport) int Min1(int x,int y,int z);

extern "C" _stdcall(dllexport) int Max1(int x,int y,int z);


2.或者
edtMax.Text:=IntToStr(Max1(Integer(4),Integer(2),Integer(3)));
edtMin.Text:=IntToStr(Min1(Integer(1),Integer(2),Integer(3)));
 
哦 谢谢各位,散分,分比较少,见谅!
 

Similar threads

I
回复
0
查看
701
import
I
I
回复
0
查看
584
import
I
I
回复
0
查看
525
import
I
顶部