Unhandled exception in XXX.exe(XXX.dll) oxC0000005:Access Violation
各位大神帮帮忙啊!!!!
想用QT 调用vc++创建的MFC Regular dll ,在编写dll时执行到n1500controller.cpp的如下语句
m_nProtocol = nProtocol;
m_nCom = nCom;
m_nControllerID= ControllerID;
时报错:
Unhandled exception in QTtest.exe(N1500USB.DLL):
0xC0000005:Access Violation.
代码如下:
(1)
//n1500controller.h : Declaration of the n1500controller
#ifndef __N1500CONTROLLER_H__
#define __N1500CONTROLLER_H__
#include "resource.h" // main symbols
#include "SerialPort.h"
#include <afxtempl.h>
class n1500controller
{
public:
n1500controller();
virtual ~n1500controller();
bool OpenGstCom(unsigned char nCom, unsigned char ControllerID, unsigned char nProtocol);
bool UpDevice(unsigned char nControllerID, unsigned char nLoop, unsigned char nAddress);
private:
CString DevideHexChar(char HexChar);
bool IsReplied(int nResultBytes, DWORD nTimeout/*,int chEnd*/);//chEnd=-1
bool DataVerify(int nStart, int nEnd);
protected:
CSerialPort m_SerialPort;
unsigned char m_nProtocol;
unsigned char m_nCom;
unsigned char m_nControllerID;
bool m_bGstComOpened;
};
#endif // __N1500CONTROLLER_H__
(2)
// n1500controller.cpp: implementation of the n1500controller class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "N1500USB.h"
#include "n1500controller.h"
#include <assert.h>
#include <afxtempl.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
n1500controller::n1500controller()
{
m_nProtocol=NULL;
m_nCom=NULL;
m_nControllerID=NULL;
m_bGstComOpened=false;
}
n1500controller::~n1500controller()
{
}
CString n1500controller::DevideHexChar(char HexChar)
{
CString result=_T("");
int temp=(HexChar&0xF0)>>4;
if(temp<10)
result+=(temp+'0');
else
result+=(temp+'A'-10);
temp=HexChar&0x0F;
if(temp<10)
result+=(temp+'0');
else
result+=(temp+'A'-10);
return result;
}
bool n1500controller::IsReplied(int nResultBytes, DWORD nTimeout/*,int chEnd*/)//chEnd=-1
{
//等待应答
if(m_SerialPort.ReceiveChar(nResultBytes))
return true;
else
return false;
}
bool n1500controller::DataVerify(int nStart, int nEnd)
{
unsigned char Sum = 0;
for (int i=nStart;i<nEnd;i++)
{
//Sum += m_SerialPort.m_chInputArray.GetAt(i);
}
//if (Sum == m_SerialPort.m_chInputArray.GetAt(nEnd))//和校验,等于校验位。
return true;
// else
// return false;
}
/************************* openGstCom **********************/
bool n1500controller::OpenGstCom(unsigned char nCom, unsigned char ControllerID, unsigned char nProtocol)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
m_nProtocol = nProtocol;
m_nCom = nCom;
m_nControllerID= ControllerID;
//参数合法性检查
int nBaud=19200;
int nBuffer = 1024;
char chParity='N';
if (nProtocol!=230)
return false;
/*if(m_bGstComOpened)
m_SerialPort.CloseCom();*/
if (!m_SerialPort.InitPort(nCom,nBaud,chParity,8,1,EV_RXCHAR,nBuffer))
return false;
else
{
m_bGstComOpened = true;
return true;
}
}