当前位置: 代码迷 >> PB >> 声明一API函数解决方案
  详细解决方案

声明一API函数解决方案

热度:105   发布时间:2016-04-29 08:38:28.0
声明一API函数
function Read_EMSNR(Port: Integer; SNR: PChar; Beep: Integer):Integer; DELPHI7开发的

说明:读EM4469卡序列号函数。
参数说明:
  Port: 通讯口号1、2、3、4分别代表串口COM1、COM2、COM3、COM4(范围 1------4)

  SNR:卡序列号(8位字符串) 

Beep:蜂鸣器蜂鸣(0代表蜂鸣,1代表不蜂鸣)



以下是DELPHI的演示例子。现在要求帮忙写一下PB9如何实现。



procedure TfrmMain.btnReadSNRClick(Sender: TObject);
var
  CardSNR: array[0..3] of Byte;
  i: Integer;
  tmpString: string;
  CardSerialNo: array[0..7] of Byte;
begin
  edtCardSNR.Text := '';
  if cmbReaderModel.ItemIndex = 1 then
  begin
  if Read_EMSNR(cmbPort.ItemIndex + 1, @CardSNR[0], cmbBeep.ItemIndex) = 0 then
  begin
  for i := 0 to 3 do
  edtCardSNR.Text := edtCardSNR.Text + IntToHex(CardSNR[i], 2);
  end else ShowMessage('读卡失败.');
  end else
  begin
  //if Read_MFSNR(cmbPort.ItemIndex + 1, @CardSNR[0]) = 0 then
  if Read_MFSNR(cmbPort.ItemIndex + 1, @CardSerialNo[0], cmbBeep.ItemIndex) = 0 then
  begin
  for i := 0 to 3 do
  tmpString := tmpString + IntToHex(CardSerialNo[i], 2);
  ShowMessage('功能卡序列号:' + tmpString);
  end else ShowMessage('读卡失败.');
  end;
end;

------解决方案--------------------
你需要知道这些参数的类型,然后才能声明,参考如下:
FUNCTION ulong AbortDoc(ulong hdc) LIBRARY "gdi32.dll"
FUNCTION ulong AbortPath(ulong hdc) LIBRARY "gdi32.dll"
FUNCTION ulong AbortPrinter(ulong hPrinter) LIBRARY "winspool.drv"
FUNCTION ulong AbortSystemShutdown(ref string lpMachineName) LIBRARY "advapi32.dll" ALIAS FOR "AbortSystemShutdownA"
FUNCTION ulong AccessCheck(ref SECURITY_DESCRIPTOR pSecurityDescriptor,ulong ClientToken,ulong DesiredAccess,ref GENERIC_MAPPING GenericMapping,ref PRIVILEGE_SET PrivilegeSet,ref ulong PrivilegeSetLength,ref ulong GrantedAccess,ulong Status) LIBRARY "advapi32.dll"
FUNCTION ulong AccessCheckAndAuditAlarm(ref string SubsystemName,ref Any HandleId,ref string ObjectTypeName,ref string ObjectName,ref SECURITY_DESCRIPTOR SecurityDescriptor,ulong DesiredAccess,ref GENERIC_MAPPING GenericMapping,ulong ObjectCreation,ref ulong GrantedAccess,ulong AccessStatus,ulong pfGenerateOnClose) LIBRARY "advapi32.dll" ALIAS FOR "AccessCheckAndAuditAlarmA"
FUNCTION ulong ActivateKeyboardLayout(ulong HKL,ulong flags) LIBRARY "user32.dll"
FUNCTION ulong AddAccessAllowedAce(ref ACL pAcl,ulong dwAceRevision,ulong AccessMask,ref Any pSid) LIBRARY "advapi32.dll"
FUNCTION ulong AddAccessDeniedAce(ref ACL pAcl,ulong dwAceRevision,ulong AccessMask,ref Any pSid) LIBRARY "advapi32.dll"
FUNCTION ulong AddAce(ref ACL pAcl,ulong dwAceRevision,ulong dwStartingAceIndex,ref Any pAceList,ulong nAceListLength) LIBRARY "advapi32.dll"
FUNCTION Integer AddAtom(ref string lpString) LIBRARY "kernel32.dll" ALIAS FOR "AddAtomA"
FUNCTION ulong AddAuditAccessAce(ref ACL pAcl,ulong dwAceRevision,ulong dwAccessMask,ref Any pSid,ulong bAuditSuccess,ulong bAuditFailure) LIBRARY "advapi32.dll"
FUNCTION ulong AddFontResource(ref string lpFileName) LIBRARY "gdi32.dll" ALIAS FOR "AddFontResourceA"
FUNCTION ulong AddForm(ulong hPrinter,ulong Level,ref Byte pForm) LIBRARY "winspool.drv" ALIAS FOR "AddFormA"
FUNCTION ulong AddJob(ulong hPrinter,ulong Level,ref Byte pData,ulong cdBuf,ref ulong pcbNeeded) LIBRARY "winspool.drv" ALIAS FOR "AddJobA"
FUNCTION ulong AddMonitor(ref string pName,ulong Level,ref Byte pMonitors) LIBRARY "winspool.drv" ALIAS FOR "AddMonitorA"
FUNCTION ulong AddPort(ref string pName,ulong hwnd,ref string pMonitorName) LIBRARY "winspool.drv" ALIAS FOR "AddPortA"
  相关解决方案