|
本帖最后由 仙乃日 于 2017-2-24 16:31 编辑
C++中的 unsigned char* 类型数据转换成AU3要写成什么?int 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,
4
unsigned char *ucGrantDept,
int &iGrantDeptLen,
unsigned char *ucUserLifeBegin,
int &iUserLifeBeginLen,
unsigned char *ucUserLifeEnd,
int &iUserLifeEndLen,
unsigned char *errMsg,
int &iErrMsgLen,
int nTimeOut);
参数说明:
【in】 int iPort, COM 口 是 1-9 USB 口是 1001-1016
【out】 unsigned char *ucName, //姓名
【out】 int &iNamelen,
【out】 unsigned char *ucSex, //性别
【out】 int &iSexLen,
【out】 unsigned char *ucIDNo, //身份证号
【out】 int &iIDNoLen,
【out】 unsigned char *ucNation, //民族
【out】 int &iNationLen,
【out】 unsigned char *ucBirthday, //生日
【out】 int &iBirthdayLen,
【out】 unsigned char *ucAddress, //地址
【out】 int &iAddressLen,
【out】 unsigned char *ucGrantDept, //签发机关
【out】 int &iGrantDeptLen,
【out】 unsigned char *ucUserLifeBegin, //有效开始日期
【out】 int &iUserLifeBeginLen,
【out】 unsigned char *ucUserLifeEnd, //有效结尾日期
【out】 int &iUserLifeEndLen,
【out】 unsigned char *errMsg, //错误信息
【out】 int &iErrMsgLen,
【in】 int nTimeOut //超时时间
* 返回值 0 成功 -1 失败 -2 超时 -3 取消
#include <array.au3>
Local $t_name = DllStructCreate("char szText[1024]")
If @error Then MsgBox(0,0,@error)
Local $p_name = DllStructGetPtr($t_name)
Local $Namelen = 0
Local $t_sex = DllStructCreate("char szText[1024]")
Local $p_sex = DllStructGetPtr($t_sex)
Local $SexLen = 0
Local $t_IDNo = DllStructCreate("char szText[1024]")
Local $p_IDNo = DllStructGetPtr($t_IDNo)
Local $IDNoLen = 0
Local $t_Nation = DllStructCreate("char szText[1024]")
Local $p_Nation = DllStructGetPtr($t_Nation)
Local $NationLen = 0
Local $t_Birthday = DllStructCreate("char szText[1024]")
Local $p_Birthday = DllStructGetPtr($t_Birthday)
Local $BirthdayLen = 0
Local $t_Address = DllStructCreate("char szText[1024]")
Local $p_Address = DllStructGetPtr($t_Address)
Local $AddressLen = 0
Local $t_GrantDept = DllStructCreate("char szText[1024]")
Local $p_GrantDept = DllStructGetPtr($t_GrantDept)
Local $GrantDeptLen = 0
Local $t_UserLifeBegin = DllStructCreate("char szText[1024]")
Local $p_UserLifeBegin = DllStructGetPtr($t_UserLifeBegin)
Local $UserLifeBeginLen = 0
Local $t_UserLifeEnd = DllStructCreate("char szText[1024]")
Local $p_UserLifeEnd = DllStructGetPtr($t_UserLifeEnd)
Local $UserLifeEndLenn = 0
Local $t_errMsg = DllStructCreate("char szText[1024]")
Local $p_errMsg = DllStructGetPtr($t_errMsg)
Local $errMsgLenn = 0
$aDllCallReturn = DllCall("IdReaderApiComm.dll", _
"int", "ReadIDCardComm", _
"int", 1001, _
"ptr", $p_name, "int", $Namelen, _
"ptr", $p_sex, "int", $SexLen, _
"ptr", $p_IDNo, "int", $IDNoLen, _
"ptr", $p_Nation, "int", $NationLen, _
"ptr", $p_Birthday, "int", $BirthdayLen, _
"ptr", $p_Address, "int", $AddressLen, _
"ptr", $p_GrantDept, "int", $GrantDeptLen, _
"ptr", $p_UserLifeBegin, "int", $UserLifeBeginLen, _
"ptr", $p_UserLifeEnd, "int", $UserLifeEndLenn, _
"ptr", $p_errMsg, "int", $errMsgLenn, _
"int", 10000)
Local $name = DllStructGetData($t_IDNo, "szText")
MsgBox(0,$name,$aDllCallReturn[0])
_ArrayDisplay($aDllCallReturn)
以下是C++的源码CStringAUsignedCharToCStringA(const unsigned char *buf,int iLen)
{
int iFixLen=iLen/2*2;
wstring wT;
int iT;
5
for (int i=0;i<iFixLen;i=i+2)
{
iT=buf[i]*256+buf[i+1];
wT+=(wchar_t)iT;
}
CStringAstr(wT.c_str());
return str;
}
void CYLzIdReaderDemoDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
int iPort=3;
int iTimeout=10000;
char errMsg[1024];
memset(errMsg,'\0',sizeof(errMsg));
unsigned char ucName[256];
memset(ucName,'\0',sizeof(ucName));
int iNamelen=0;
unsigned char ucSex[256];
memset(ucSex,'\0',sizeof(ucSex));
int iSexLen=0;
unsigned char ucIDNo[256];
memset(ucIDNo,'\0',sizeof(ucIDNo));
int iIDNoLen=0;
unsigned char ucNation[256];
memset(ucNation,'\0',sizeof(ucNation));
int iNationLen=0;
unsigned char ucBirthday[256];
memset(ucBirthday,'\0',sizeof(ucBirthday));
int iBirthdayLen=0;
unsigned char ucAddress[256];
memset(ucAddress,'\0',sizeof(ucAddress));
int iAddressLen=0;
unsigned char ucGrantDept[256];
memset(ucGrantDept,'\0',sizeof(ucGrantDept));
int iGrantDeptLen=0;
unsigned char ucUserLifeBegin[256];
memset(ucUserLifeBegin,'\0',sizeof(ucUserLifeBegin));
int iUserLifeBeginLen=0;
unsigned char ucUserLifeEnd[256];
6
memset(ucUserLifeEnd,'\0',sizeof(ucUserLifeEnd));
int iUserLifeEndLen=0;
unsigned char ucErrMsg[256];
memset(ucErrMsg,'\0',sizeof(ucErrMsg));
int iErrMsgLen=0;
int iRet=ReadIDCardComm(
iPort,
ucName,
iNamelen,
ucSex,
iSexLen,
ucIDNo,
iIDNoLen,
ucNation,
iNationLen,
ucBirthday,
iBirthdayLen,
ucAddress,
iAddressLen,
ucGrantDept,
iGrantDeptLen,
ucUserLifeBegin,
iUserLifeBeginLen,
ucUserLifeEnd,
iUserLifeEndLen,
ucErrMsg,
iErrMsgLen,
iTimeout);
if(0!=iRet)
{
CString strErrMsg="";
if (-2==iRet)
{
strErrMsg=strErrMsg+"读取身份证超时";
}
else
{
CString strT="";
strT=strT+UsignedCharToCStringA(ucErrMsg,iErrMsgLen);
int a=iErrMsgLen;
7
strErrMsg=strErrMsg+"读卡错误:"+strT;
}
return ;
}
CString m_strName=UsignedCharToCStringA(ucName,iNamelen);
CString m_strSex=UsignedCharToCStringA(ucSex,iSexLen);
CString m_strSfzNo=UsignedCharToCStringA(ucIDNo,iIDNoLen);
CString m_strNation=UsignedCharToCStringA(ucNation,iNationLen);
CString m_strBirthday=UsignedCharToCStringA(ucBirthday,iBirthdayLen);
CString m_strAddress=UsignedCharToCStringA(ucAddress,iAddressLen);
CString m_strGrantDept=UsignedCharToCStringA(ucGrantDept,iGrantDeptLen);
CString m_strUserLifeBegin=UsignedCharToCStringA(ucUserLifeBegin,iUserLifeBeginLen);
CString m_strUserLifeEnd=UsignedCharToCStringA(ucUserLifeEnd,iUserLifeEndLen);
}
谢谢大家的帮忙。使用用DLLcall时,无论怎么写都无法获取结果。改用ActiveX 控件对象方法,结果可以啦。#PRE_UseX64=n
$oScript = ObjCreate("IDCARDREADER.IdCardReaderCtrl.1")
$oScript.SetTimeout(5000); //设置读取超时时间
$oScript.SetPort(1001); //设置 com 口号或 usb 后号
$oScript.SetPicPath("Z:\\ZP.bmp")
$iRet=$oScript.ReadIDCard(); //开始读取
If $iRet<>0 Then MsgBox(0,0,$oScript.GetErrMsg())
MsgBox(0,"身份证号",$oScript.GetIDNo())
|
|