C++调用一卡通DLL崩溃异常,在线等~~~
/********* 厂家的接口文档说明如下: *****/
函数名称及说明
1) 打开串口
int IniCom(int ComPort,int BaudRate)
入口参数:
ComPort: 串口
BaudRate: 通讯波特率,推荐取值为:0 即19200
返回值:0:成功
2) 扣卡金额
int DecCard (int ComPort, unsigned char *CardNum,int DecMoney)
入口参数: CardNum: 10字节卡显示卡号(ASCII码)
DecMoney: 要扣除的金额
出口参数:无
返回值:0:成功
/********* 我写的测试程序: *****/
typedef int (_stdcall PfnIniCom) (int , int );
typedef int (_stdcall PfnDecCard) (int , unsigned char *,int );
extern "C" __declspec(dllexport) int _stdcall IniCom(int ComPort, int BaudRate);
extern "C" __declspec(dllexport) int _stdcall DecCard(int ComPort, unsigned char *CardNum,int DecMoney);
void CSmartReadWinDlg::OnBnClickedBtnDeduct()
{
LPCTSTR lpszModuleName = _T("SmartCom411SFJ.dll");
HINSTANCE hInstLib = AfxLoadLibrary(lpszModuleName);
PfnIniCom *fnIniCom = NULL;
PfnDecCard *fnDecCard = NULL;
int ComPort = 1;
int DecMoney =1 ;
int retVal;
int BaudRate = 0;
retVal = 1;
fnIniCom = (PfnIniCom *) GetProcAddress(hInstLib,(LPCSTR)("IniCom"));
fnDecCard = (PfnDecCard *) GetProcAddress(hInstLib,(LPCSTR)("DecCard"));
retVal = fnIniCom(ComPort,BaudRate); //打开串口,返回0,即已经成功
unsigned char strcardNum[11] = {"0000012016"}; // cardNum在读卡器上,而且能读到卡信息
retVal = fnDecCard( ComPort, strcardNum,DecMoney); // 此处函数崩溃,异常提示如下 // 异常提示:Unhandled exception at 0x10007c27 in SmartReadWin.exe: 0xC0000005: Access violation reading location 0x00000001.}
}
[解决办法]
fnDecCard = (PfnDecCard *) GetProcAddress(hInstLib,(LPCSTR)("DecCard"));
获取DecCard失败了吧
[解决办法]
int DecCard (int ComPort, unsigned char *CardNum,int DecMoney)
入口参数: CardNum: 10字节卡显示卡号(ASCII码)
你定义的确是unsigned char strcardNum[11] = {"0000012016"};
11位啊,参数不匹配
[解决办法]
unsigned char strcardNum[10] = {0,0,0,0,0,1,2,0,1,6};
那楼主这样修改下呢?