S
sosmao
Unregistered / Unconfirmed
GUEST, unregistred user!
大家好:我用的是Delphi 7.公司有一考勤机器,厂商提供有考勤机Dll文件.<br>我需要调用Dll文件中对应的函数读取其中的值.其中Dll文件说明如下:JBC2900E.dll函数说明<br><br>注:所有的AR_ID变量代表卡钟地址编号.JBC2900E型地址编号为1-128.<br>--------------------------------------------------------------------------------<br> extern "C" __declspec(dllimport ) __stdcall <br>long Open_ComX(char * ComPort,long Baud);<br>功能:打开串口<br>参数: ComPort<br>端口号 如'COM1' `COM2'<br>Baud 波特率 9600<br>回车:<br>0 成功 非0失败<br>--------------------------------------------------------------------------------<br>extern "C" __declspec(dllimport ) __stdcall <br>long Close_ComX();<br>功能:关闭串口<br>回车:<br>0 成功 非0失败<br>--------------------------------------------------------------------------------<br>extern "C" __declspec(dllimport ) __stdcall <br>long SearchAR(long AR_ID);<br>功能:搜索卡钟<br>回车: 0 存在 非0 不存在<br>--------------------------------------------------------------------------------<br>extern "C" __declspec(dllimport ) __stdcall <br>long ReadRam2k(long AR_ID,char *DataBuff,long BlockFlag);<br>功能:读128条数据<br>参数:<br>DataBuff<br> 数据从此参数返回.<br>BlockFlag<br> 块标志.<br>返回:1 数据未完并请求下一块. 0数据完成.<br>我需要用Delphi读取考勤机的考勤记录.用厂商自带程序读出的数据如下<br>0012005091906511200003456018<br>0012005091907120900002142018<br>我的思路是:1:打开Com1口;2: 考勤机;3: 读取数据<br>前两步没问题,后面读取数据有问题.我的相关代码如下<br> private<br> { Private declarations }<br> public<br><br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> Type TOpen_ComX=Function(Comportchar;Band:Integer):Integer;Stdcall;<br> Type TSearchAR=Function(AD_ID:Integer):Integer;Stdcall;<br> Type TReadRam2k=Function(AD_ID:Integer;DataBuffChar;BlockFlag:Integer):Integer;Stdcall;<br>implementation<br>function Open_ComX(ComportChar;Band:Integer):Integer; Stdcall external 'JBC_Attend.dll'name 'Open_ComX';<br>function Search(AR_ID:Integer):Integer; Stdcall external 'JBC_Attend.dll'name 'SearchAR';<br><br><br><br>{$R *.dfm}<br>procedure TForm1.BitBtn1Click(Sender: TObject);<br><br>//功能:打开串口<br>Var<br>Open_ComX:TOpen_ComX;<br>Handle:THandle;<br>Comportchar;<br>Band:Integer;<br>begin<br> Comport:='COM1';//设置Com1口<br> Band:=9600; //设置速率<br> Handle:=LoadLibrary('JBC_Attend.dll');<br> Open_ComX:=GetProcAddress(Handle,'Open_ComX');<br> If Open_ComX(Comport,Band)=0 Then Edit1.Text:='Com1 口开启成功'<br> Else Edit1.Text:='Com1 口开启失败';<br> FreeLibrary(Handle);<br>end;<br><br><br>procedure TForm1.BitBtn2Click(Sender: TObject);<br>//功能: 搜索卡钟<br>Var<br>Search:TSearchar;<br>Handle:THandle;<br>AD_ID:Integer;<br>begin<br> AD_ID:=1;<br> Handle:=LoadLibrary('JBC_Attend.dll');<br> Try<br> Search:=GetProcAddress(Handle,'SearchAR');<br> Edit4.Text:=IntToStr(Search(AD_ID));<br> If (Search(AD_ID)=0) Then Edit2.Text:='搜索考勤 1 号机器成功'<br> Else Edit2.Text:='搜索考勤 1 号机器失败';<br> Finally<br> FreeLibrary(Handle);<br> End;<br>End;<br><br>procedure TForm1.BitBtn3Click(Sender: TObject);<br>//读128条数据<br>Var<br>ReadRam:TReadRam2k;<br>Handle:THandle;<br>farfun: TFarProc;<br>AD_ID:Integer;<br>DataBuff: PChar;<br>BlockFlag:Integer;<br>begin<br> AD_ID:=1;<br> BlockFlag:=1;<br> Handle:=LoadLibrary('JBC_Attend.dll');<br> farfun:=GetProcAddress(Handle,'ReadRam2k');<br> If farfun<>nil then<br> Begin<br> @ReadRam:=farfun;<br> ReadRam(AD_ID,DataBuff,BlockFlag);<br> Edit3.Text:='记录读取中:'+DataBuff;<br> Edit4.Text:='读取状态'+IntToStr(ReadRam(AD_ID,DataBuff,BlockFlag));<br><br> Memo1.Lines.Add(DataBuff);<br> End;<br> FreeLibrary(Handle);<br>End;<br><br>当我执行完前两步再执行读取数据时则报告如下:<br>Access Violation at Address 00242995 in module `JBC_Attend.dll ` Write of address 00427510<br>请求指教!我如何像厂商那样正常读取数据??请赋源码!!谢谢!!