标题:求助delphi 调用C++ dll 求助
只看楼主
fjkk
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-10-6
 问题点数:0 回复次数:2 
求助delphi 调用C++ dll 求助

#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;


需要加什么声明。。。求助如何动态调用。。。
搜索更多相关主题的帖子: dll extern int unsigned char 
2020-02-18 03:20
return_0
Rank: 8Rank: 8
来 自:五维空间
等 级:禁止访问
威 望:3
帖 子:512
专家分:838
注 册:2020-1-28
得分:0 
。。。

2020-02-27 19:30
supermay
Rank: 1
等 级:新手上路
威 望:1
帖 子:34
专家分:0
注 册:2004-10-3
得分:0 
要在PAS中声明tp的原型

2021-10-20 10:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-499277-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.080934 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved