各位大神幫幫忙啊!!!!
想用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;
}
}
uj5u.com熱心網友回復:
查看一下出錯的時候的函式呼叫堆疊,具體那個引數為空指標了uj5u.com熱心網友回復:
崩潰的時候在彈出的對話框按相應按鈕進入除錯,按Alt+7鍵查看Call Stack即“呼叫堆疊”里面從上到下列出的對應從里層到外層的函式呼叫歷史。雙擊某一行可將游標定位到此次呼叫的源代碼或匯編指令處,看不懂時雙擊下一行,直到能看懂為止。uj5u.com熱心網友回復:
@趙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()
感徑訓是不知所措
uj5u.com熱心網友回復:
看不懂時雙擊下一行,直到能看懂為止。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/102553.html
標籤:基礎類
