JK105Pro.dll是用C写的DLL文件,现在要在DELPHI6中调用int opencard_h(char *sReply)接口函数(整型),其中sReply是DLL调用后的返回字符串值,在DELPHI中应该如何调用啊?该接口函数好象是先在DELPHI中传入一个sReply的String,然后调用接口函数后返回sReply的值。我用DELPHI6做了以下动态调用程序,但是在调用接口函数的时候出现地址冲突的错误,请高手指点迷津,问题解决后马上给分!先谢谢了!拜托各位兄弟了!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TOpenCard_h = function(var sReply:String):Integer;stdcall;
err1=class(exception);
err2=class(exception);.......procedure TForm1.Button3Click(Sender: TObject); //打开卡片
var
filename:pchar;
DllHandle1: THandle;
opencard_h:TOpenCard_h;
i:Integer;
sReply:String;
begin
filename:=pchar(extractfilepath(application.ExeName)+'JK105Pro.dll');
DllHandle1:=loadlibrary(filename);
if DllHandle1=0 then
err2.Create('DLL调用出错')
else
@opencard_h:=GetProcAddress(DllHandle1,'opencard_h');
if not(@opencard_h=nil) then
begin
sReply:='';
i:=opencard_h(sReply);
ShowMessage(IntToStr(i)); //
end
else RaiseLastWin32Error;
//freelibrary(DllHandle1);
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TOpenCard_h = function(var sReply:String):Integer;stdcall;
err1=class(exception);
err2=class(exception);.......procedure TForm1.Button3Click(Sender: TObject); //打开卡片
var
filename:pchar;
DllHandle1: THandle;
opencard_h:TOpenCard_h;
i:Integer;
sReply:String;
begin
filename:=pchar(extractfilepath(application.ExeName)+'JK105Pro.dll');
DllHandle1:=loadlibrary(filename);
if DllHandle1=0 then
err2.Create('DLL调用出错')
else
@opencard_h:=GetProcAddress(DllHandle1,'opencard_h');
if not(@opencard_h=nil) then
begin
sReply:='';
i:=opencard_h(sReply);
ShowMessage(IntToStr(i)); //
end
else RaiseLastWin32Error;
//freelibrary(DllHandle1);
end;
解决方案 »
- 如何禁止往某个盘符或者某个目录下写文件?
- TClientDataSet中用Post的时候出现错误:at the begin of table
- 请问各位大哥,我怎样才能把Dehpi中的引用的类库(编译二进制文件.dcu文件)加入到c++builder中,请各位赐教!
- 怎么这样程序出错(treeview),请各位指点!!!
- 关于数据库连接的问题
- 怎么没有人理我
- 面对突如其来的感情难题,兄弟姐妹们,silverwonder有些话想说,同时散分给亲爱的你们!
- 请各位高手帮个忙!
- 事务问题
- 谁能告诉我关于iblocal 中的函数的用法??
- 怎么控制Dbgrid的输入长度??
- 救我啊 我快疯啦 ,谁帮我我给1000分 真的
var sReply:pchar;......
或: i:=opencard_h(pchar(sReply); ......
type
TOpenCard_h = function(sReply:Pchar):Integer;stdcall;
...
procedure TForm1.Button3Click(Sender: TObject); //打开卡片
var
filename:pchar;
DllHandle1: THandle;
opencard_h:TOpenCard_h;
i:Integer;
sReply:Array [0..100] of char;
....mrcpro(瑞雪) 的方法比较接近,谢谢了对了,怎么给分的啊?
if not(@opencard_h=nil) then
begin
sReply:='';
i:=opencard_h(sReply);//改成i:=opencard_h(pchar(sReply);
//加一句setlength(sreplay,strlen(pchar(sreplay)));
ShowMessage(IntToStr(i)); //
end
if not(@opencard_h=nil) then
begin
sReply:='';
i:=opencard_h(sReply);//改成i:=opencard_h(pchar(sReply));
setlength(sreplay,strlen(pchar(sreplay)));//加一句
ShowMessage(IntToStr(i)); //
end