注册 登录
编程论坛 Delphi论坛

求助delphi 调用C++ dll 求助

fjkk 发布于 2020-02-18 03:20, 2473 次点击

#ifndef _N_IDREADERAPI_H_
#define _N_IDREADERAPI_H_   1


#define  IDREADER_WINAPI __stdcall


#define  IDREADER_DLLEXPORT _declspec(dllexport)


    /**********************************************************************************************
    *
    * 函数名:     ReadIDCardComm
    * 功能:         读取身份证函数
    * 作者:         shz
    * 日期:         2015-6-1
    * 备注:      出参 编码为unicode 两个字节一个汉字
    *            照片解码后 会在当目录生成一个名"ZP.bmp"的身份证图片
    * 参数说明:
    *    int iPort,  COM口 是1-9 USB口是1001-1016
    *    unsigned char *ucName,  //姓名
    *    int &iNamelen,
    *    unsigned char *ucSex,   //性别
    *    int &iSexLen,
    *    unsigned char *ucIDNo,  //身份证号
    *    int &iIDNoLen,
    *    unsigned char *ucNation, //民族
    *    int &iNationLen,
    *    unsigned char *ucBirthday, //生日
    *    int &iBirthdayLen,
    *    unsigned char *ucAddress, //地址
    *    int &iAddressLen,
    *    unsigned char *ucGrantDept, //签发机关
    *    int &iGrantDeptLen,
    *    unsigned char *ucUserLifeBegin, //有效开始日期
    *    int &iUserLifeBeginLen,
    *    unsigned char *ucUserLifeEnd, //有效结尾日期
    *    int &iUserLifeEndLen,
    *    unsigned char *errMsg,  //错误信息
    *    int &iErrMsgLen,
    *    int nTimeOut           //超时时间
    * 返回值 0 成功 -1 失败 -2超时 -3取消
    *
    ***********************************************************************************************/


extern "C"  IDREADER_DLLEXPORT int IDREADER_WINAPI  ReadIDCardComm(
                          int iPort,
                          unsigned char *ucName,
                          int &iNamelen,
                          unsigned char *ucSex,
                          int &iSexLen,
                          unsigned char *ucIDNo,
                          int &iIDNoLen,
                          unsigned char *ucNation,
                          int &iNationLen,
                          unsigned char *ucBirthday,
                          int &iBirthdayLen,
                          unsigned char *ucAddress,
                          int &iAddressLen,
                          unsigned char *ucGrantDept,
                          int &iGrantDeptLen,
                          unsigned char *ucUserLifeBegin,
                          int &iUserLifeBeginLen,
                          unsigned char *ucUserLifeEnd,
                          int &iUserLifeEndLen,
                          unsigned char *errMsg,
                          int &iErrMsgLen,
                          int nTimeOut);

    /**********************************************************************************************
    *
    * 函数名:     StopReadIDCardComm
    * 功能:         取消身份证读取
    * 作者:         shz
    * 日期:         2015-6-1
    * 备注:      
    *
    ***********************************************************************************************/


extern "C"  IDREADER_DLLEXPORT void IDREADER_WINAPI StopReadIDCardComm(void);

extern "C"  IDREADER_DLLEXPORT void IDREADER_WINAPI SetPicPathComm(const char *szFilePath);

typedef struct ID_INFO
{
    char aName[50];
    char aSex[5];
    char aNation[20];
    char aBrithday[10];
    char aAddress[140];
    char ID[20];
    char aOrgan[50];
    char date[30];
    char aPassNum[20];
    char aPassCount[6];
    char aCategory[20];
}ID_INFO;
extern "C"  IDREADER_DLLEXPORT int IDREADER_WINAPI ReadIDCardCommEx (
                                                    int iPort,
                                                    ID_INFO &info,
                                                    char *errMsg,
                                                    int & iErrMsgLen,
                                                    int nTimeOut);


typedef struct FOREIGN_INFO
{
    char aEName[140];
    char aSex[20];
    char ID[40];
    char aNationCode[6];
    char aCName[30];
    char aUserLifeBegin[16];
    char aUserLifeEnd[16];
    char aBrithday[16];
    char aCardVersion[4];
    char aCategoryCode[8];
    char aCardType[50];
    char aSaveAred[6];
}FOREIGN_INFO;
extern "C"  IDREADER_DLLEXPORT int IDREADER_WINAPI ReadForeignIDCard (
                                                    int iPort,
                                                    FOREIGN_INFO &info,
                                                    char *errMsg,
                                                    int & iErrMsgLen,
                                                    int nTimeOut);

extern "C"  IDREADER_DLLEXPORT int IDREADER_WINAPI GetIDCardType (int iPort,char *errMsg);
#endif






如何用delphi 动态调用


procedure TForm1.Button1Click(Sender: TObject);
var
th:Thandle;
tp:Tfarproc;
begin
 th:= loadlibrary('Idreaderapicomm.dll'); //装载dll
 if th>0 then
 begin
 // memo1.Lines.Insert(0,'装载 Idreaderapicomm.dll 成功!');
  tp:=getprocaddress(th,pchar('ReadIDCardComm'));
  if assigned(tp) then
  begin
   memo1.Text := tp
  end;

 end
 else
 begin
  showmessage('Idreaderapicomm.dll 没有找到!');
 end;


end;


需要加什么声明。。。求助如何动态调用。。。
2 回复
#2
return_02020-02-27 19:30
。。。
#3
supermay2021-10-20 10:29
要在PAS中声明tp的原型
1