Unhandled exception in XXX.exe(XXX.dll) oxC0000005:Access Violation

qq_24532765 2017-04-26 09:01:42
各位大神帮帮忙啊!!!!
想用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;
}
}
...全文
367 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2017-04-26
  • 打赏
  • 举报
回复
看不懂时双击下一行,直到能看懂为止。
qq_24532765 2017-04-26
  • 打赏
  • 举报
回复
@赵4老师 按照你的指示做了 如下: n1500controller::OpenGstCom(int 4, int 1, int 230) line 68 + 6 bytes QTTEST! 00401802() QTTEST! 00401a26() QTTEST! 00401b06() QTCORED4! 6a20611c() QTCORED4! 6a216ab8() QTGUID4! 69580b38() QTGUID4! 692ee953() QTGUID4! 692ee8d1() QTGUID4! 692efd7d() QTGUID4! 68fb6ad8() QTGUID4! 692efc08() QTGUID4! 6938e9e2() QTGUID4! 68f6bd88() QTGUID4! 68f69fd1() QTCORED4! 6a201664() QTGUID4! 695e8182() QTGUID4! 68f687e0() QTGUID4! 68fd3637() QTGUID4! 68fce482() 754962fa() 75496d3a() 754977c4() 7549788a() QTCORED4! 6a225e76() QTGUID4! 68fccf40() QTCORED4! 6a1ff672() QTCORED4! 6a1ff79a() QTCORED4! 6a201c94() QTGUID4! 68f69324() QTTEST! 00401400() QTTEST! 00401f32() QTTEST! 00401c58() QTTEST! 0040124b() QTTEST! 004012b8() KERNEL32! 751f336a() NTDLL! 770c9902() NTDLL! 770c98d5() 感觉还是不知所措
赵4老师 2017-04-26
  • 打赏
  • 举报
回复
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack即“调用堆栈”里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止
oyljerry 2017-04-26
  • 打赏
  • 举报
回复
查看一下出错的时候的函数调用堆栈,具体那个参数为空指针了

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧