打开函数时出错
////fzyktclient.dll 中的ykt_readopencardno_local函数及参数无误, 行158出错 提示THIS指针为空 , 帮助看看是哪出错了#include<windows.h>
#include<stdlib.h>
#include<string.h>
#include<iostream.h>
#include<stdio.h>
//#include<ClassHeader.h>///接口类
///接口类定义
class IckJk {
public:
IckJk (); //默认构造函数
~IckJk (); //析构函数
void ykt_open (void);//初始化
void ykt_ReadNo(void); //
void ykt_close(void); //关闭
void ykt_readinfo(void);
void temp1(void);
int read_YesOrNo() const;
char read_pCardno() ;
private:
// HINSTANCE hinstance;//DLL句柄
char *test;
int YesOrNo; //函数调用时是否成功
int nDeviceType; //设备类型(10或12)
int nCom; //端口(0-9) 0 - com1 1 - com2 … 9 - usb
int nBaud;//波特率(1-4) 1 - 9600 2 - 19200 3 - 28800 4 - 57600 建议用3或者2
char *pRegion;//地区编号 3500代表省本级 Char(4)
char *pWarnmsg;//警告信息 Char(1024)
char *pErrmsg;//错误信息 Char(1024)
char *pDeptID;//网点编号
char *pDeptKey;// 网点密钥
char *pCardtype;//
char *pCardno;//
char *pIssuedeptid;//
char *pIssuedate;//
char *pIdtype;//
char *pId;//
char *pName;//
char *pSex;//
char *pBirthDate;//
char *pCompany;//
char *pAddress;//
char *pTelephone;//
int offset;//
int length;//
char *pData;//
};
//稳定初始状态
IckJk::IckJk ()
{
nDeviceType = 12; //设备类型(10或12)
nCom = 0; //端口(0-9) 0 - com1 1 - com2 … 9 - usb
nBaud = 2; //波特率(1-4) 1 - 9600 2 - 19200 3 - 28800 4 - 57600 建议用3或者2
pRegion = "3508" ;//地区编号 3500代表省本级 Char(4)
pWarnmsg="-warn-";
pErrmsg="-err-";
pDeptID= "0104" ;
pDeptKey= "" ; //
pCardtype="F";
pCardno = "-card-";
offset = 0;//
length= 8 ;//
pData="8";//
YesOrNo=9;
test= " -test- " ;//
}
//析构函数
IckJk::~IckJk (){
}
void IckJk::temp1()
{
cout<<"YesOrNo "<<YesOrNo ;
cout<<"pWarnmsg "<<pWarnmsg ;
cout<<"pErrmsg "<<pErrmsg ;
cout<<"pCardno "<<pCardno ;
}
int IckJk::read_YesOrNo() const
{
return YesOrNo;
}
char IckJk::read_pCardno(void)
{
return (*pCardno);
}
extern "C" __declspec(dllimport) int ykt_opendevice(int ,int ,int ,char *,char *,char *);
void IckJk::ykt_open(void) //初始化
{
//
typedef int(WINAPI *ykt_opendevice)(int nDeviceType,int nCom,int nBaud,LPCTSTR str ,char *pWarnmsg,char *pErrmsg);
//---定义
HINSTANCE hinstance;//DLL句柄
hinstance=LoadLibrary("fzyktclient.dll");
cout<<hinstance;
if(hinstance)
{
ykt_opendevice funopendevice=NULL;
funopendevice=(ykt_opendevice)GetProcAddress(hinstance,"ykt_opendevice");
// //GetProcAddress得到了所加载DLL模块中函数ykt_opendevice的地址并赋给了funopendevice
if(funopendevice)
{
cout<<funopendevice;
YesOrNo=1;
YesOrNo=funopendevice(nDeviceType,nCom,nBaud,pRegion,pWarnmsg,pErrmsg);
cout<<YesOrNo;
if (YesOrNo != 0)
{ if (pWarnmsg == NULL)
{IckJk::pWarnmsg = "警告:请先正确设置串口!";}
else
{IckJk::pWarnmsg = pWarnmsg ;}
if (pErrmsg == NULL)
{IckJk::pErrmsg = "错误:打开失败!";}
else
{IckJk::pErrmsg = pErrmsg ;}
}
else
{
cout<<"打开成功";
cout<<YesOrNo;
}
} //if(funopendevice)
} //if(hinstance)
FreeLibrary(hinstance);//卸载fzyktclient.dll文件;
}
extern "C" __declspec(dllimport) int readno_local(LPCTSTR , char *,char *, char * ,char * , char *,char *);
void IckJk::ykt_ReadNo(void) //脱机读取卡号
{
//
typedef int(WINAPI *readno_local)(LPCTSTR str, char *pDeptID,char *pDeptKey, char *pCardtype,char *pCardno, char *pWarnmsg,char *pErrmsg);
//---定义
HINSTANCE hinstance;//DLL句柄
hinstance=LoadLibrary("fzyktclient.dll");
cout<<hinstance;
if(hinstance)
{
readno_local funreadno_local=NULL;
funreadno_local=(readno_local)GetProcAddress(hinstance,"ykt_readopencardno_local");
// //GetProcAddress得到了所加载DLL模块中函数ykt_opendevice的地址并赋给了funopendevice
if(funreadno_local)
{
cout<<funreadno_local;
YesOrNo=2;
//下一行出错 测试时提示内存为空, 函数参数无误
YesOrNo=funreadno_local(pRegion,pDeptID,pDeptKey,pCardtype,pCardno,pWarnmsg,pErrmsg);
cout<<YesOrNo;
if (YesOrNo != 0)
{
IckJk::pWarnmsg = pWarnmsg;
IckJk::pErrmsg = pErrmsg;
}
else
{
cout<<"读卡号成功";
cout<<YesOrNo;
}
} //if(funopendevice)
} //if(hinstance)
FreeLibrary(hinstance);
}
//extern "C" __declspec(dllimport) int ykt_readopencardno_local(char *, char *,char *, char * ,char * , char *,char *);
extern "C" __declspec(dllimport) int ykt_readopencardinfo_local(char *, char *,char *, char *,char *, char *,char *,char *,char *,char *, char *,char *,char *,char *,char *, char *,char *);
extern "C" __declspec(dllimport) int ykt_closedevice(char *, char *);
void main(void)
{
IckJk t;
t.ykt_open();
if (! t.read_YesOrNo())
{
cout<<"a";
t.ykt_ReadNo();
}
// t.ykt_readinfo ();
if (! t.read_YesOrNo())
{
cout<<"b";}
// t.ykt_close();
if (! t.read_YesOrNo())
{cout<<"c"; }
t.temp1();
}