dll结构
type
TCardInfo = packed record // the Communication Block used in both parts (Server+Client)
consequence: Integer; //标志
H_cardsn: array[0..9] of char; //卡序列号
Name: array[0..15] of char; //姓名
Sex: array[0..1] of char; //性别
end;
pCardInfo = ^TCardInfo;函数
function ReadCard1(var tag_: Integer; RCardInfo:pCardInfo): integer; stdcall;
begin
getMem(_pCardInfo, sizeof(TCardInfo));
_pCardInfo^.consequence := 0;
StrPCopy(_pCardInfo^.H_cardsn, '0000FFFFFF');//卡序列号
StrPCopy(_pCardInfo^.Name, '张三'); //姓名
StrPCopy(_pCardInfo^.Sex, '男'); //性别
RCardinfo := _pCardInfo;
freemem(_pCardInfo);
end;现在我要在主程序中调用DLL
function ReadCard1(tag_: Integer; RCardInfo: pCardInfo): integer; stdcall; external 'ReadCard.dll' name 'ReadCard1';
procedure TForm1.btn1Click(Sender: TObject);
var i: Integer;
str: string;
CardInfo: TCardInfo;
begin
try
ReadCard1(0, @CardInfo);
edt3.Text := string(CardInfo.H_cardsn);
except
on e: exception do
showmessage(e.Message);
end;
end;
现在主程序调用时提示‘read of address 00000000’
请问我上面的DLL程序和主程序是否都写的正确,不知为何会出错。求解。谢谢
我是想在主程序中取出DLL中返回的结构中的值,请问该如何做?
type
TCardInfo = packed record // the Communication Block used in both parts (Server+Client)
consequence: Integer; //标志
H_cardsn: array[0..9] of char; //卡序列号
Name: array[0..15] of char; //姓名
Sex: array[0..1] of char; //性别
end;
pCardInfo = ^TCardInfo;函数
function ReadCard1(var tag_: Integer; RCardInfo:pCardInfo): integer; stdcall;
begin
getMem(_pCardInfo, sizeof(TCardInfo));
_pCardInfo^.consequence := 0;
StrPCopy(_pCardInfo^.H_cardsn, '0000FFFFFF');//卡序列号
StrPCopy(_pCardInfo^.Name, '张三'); //姓名
StrPCopy(_pCardInfo^.Sex, '男'); //性别
RCardinfo := _pCardInfo;
freemem(_pCardInfo);
end;现在我要在主程序中调用DLL
function ReadCard1(tag_: Integer; RCardInfo: pCardInfo): integer; stdcall; external 'ReadCard.dll' name 'ReadCard1';
procedure TForm1.btn1Click(Sender: TObject);
var i: Integer;
str: string;
CardInfo: TCardInfo;
begin
try
ReadCard1(0, @CardInfo);
edt3.Text := string(CardInfo.H_cardsn);
except
on e: exception do
showmessage(e.Message);
end;
end;
现在主程序调用时提示‘read of address 00000000’
请问我上面的DLL程序和主程序是否都写的正确,不知为何会出错。求解。谢谢
我是想在主程序中取出DLL中返回的结构中的值,请问该如何做?
解决方案 »
- 用什么方法能得到MonthCalendar的一个月中第一天和最后一天,跨年时出问题了。
- UPDATE SET 简单的问题
- 有关dll之间信息传递问题
- 怎么声明type library里的method
- Com/Dcom三成系统问题
- 那位高手有航空模拟系统的开发经验?能否给小弟指导一下。在线
- 200,再线等待,我的控件为什么编译出错???
- 求助:已经注册的Borland C++builder6和Delphi为何突然又需要注册?
- 在QReport中,多行显示时,QRBand的宽度不够,怎么在运行状态下让QRBand的宽度自动增加???
- 如何实现在DBGrid中选中一条记录,拖拽到TImage上就将它删除?
- delphi数据库*表
- cxgrid 中lookupcombox问题
function ReadCard1(var tag_: Integer; RCardInfo:pCardInfo): integer; stdcall;
begin
if Assigned(RCardInfo) then
begin
RCardInfo^.consequence := 0;
StrPCopy(RCardInfo^.H_cardsn, '0000FFFFFF');//卡序列号
StrPCopy(RCardInfo^.Name, '张三'); //姓名
StrPCopy(RCardInfo^.Sex, '男'); //性别
Result:= 0;
end
else begin
result:= -1;
end;
end;你调用的那段代码就不要改了, 就那么写
这段代码也不要加string强制转换
RCardInfo: TCardInfo;
调用:
ReadCard1(0, @RCardInfo);另:把ReadCard1里面的 getMem和 freemem去掉
access violation at address 30323130.read of address 30323130 的错误,不知是什么原因。跟踪后发现整个程序段已经运行完了。都END结束了,可以就在跳出END的时候报错了,不知为什么?