Want to use QT call MFC of vc + + to create Regular DLL, in writing a DLL to n1500controller. The following statement of CPP
M_nProtocol=nProtocol;
M_nCom=nCom;
M_nControllerID=ControllerID;
Times wrong:
Unhandled exception in QTtest. Exe (N1500USB. DLL) :
0 xc0000005: Access Violation.
The code is as follows:
(1)
//n1500controller. H: Declaration of the n1500controller
# # ifndef __N1500CONTROLLER_H__
# define __N1500CONTROLLER_H__
# include "resource. H"//the main symbols
# include "SerialPort. H"
# include & lt; Afxtempl. H>
The 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:
Cstrings DevideHexChar (char HexChar);
Bool IsReplied (int nResultBytes, dwords 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 & lt; Assert. H>
# include & lt; Afxtempl. H>
//////////////////////////////////////////////////////////////////////
//Construction/Destruction
//////////////////////////////////////////////////////////////////////
N1500controller: : n1500controller ()
{
M_nProtocol=NULL;
M_nCom=NULL;
M_nControllerID=NULL;
M_bGstComOpened=false;
}
N1500controller: : ~ n1500controller ()
{
}
Cstrings n1500controller: : DevideHexChar (char HexChar)
{
Cstrings result=_T (" ");
Int temp=(HexChar& 0 xf0) & gt;> 4.
If (temp<10)
The result +=(temp + '0');
The else
The result +=(temp + 'A' - 10);
Temp=HexChar& 0 x0f;
If (temp<10)
The result +=(temp + '0');
The else
The result +=(temp + 'A' - 10);
return result;
}
Bool n1500controller: : IsReplied (int nResultBytes, dwords nTimeout/*, int chEnd */)//chEnd=1
{
//wait reply
If (m_SerialPort ReceiveChar (nResultBytes))
return true;
The else
return false;
}
Bool n1500controller: : DataVerify (int nStart, int nEnd)
{
Unsigned char Sum=0;
For (int I=nStart; I
//Sum +=m_SerialPort. M_chInputArray. GetAt (I);
}
//if (Sum==m_SerialPort. M_chInputArray. GetAt (nEnd))//calibration, and equal to check digit,
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;
//parameter validation check
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;
The else
{
M_bGstComOpened=true;
return true;
}
}
CodePudding user response:
Check the error of the function call stack, when the parameter is a null pointerCodePudding user response:
Collapsed in the pop-up dialog box, press the corresponding button to enter debugging press Alt + 7 key to view the Call Stack, namely "the Call Stack" from the inside to the following out of from the inner to outer function Call history, double-click a row to the cursor to the Call of the source code or assembly instruction, don't understand when double click on the next line, until we can read ,CodePudding user response:
@ 4 teacher zhaoIn accordance with your instructions do
As follows:
N1500controller: : OpenGstCom (int 4, int, int) 230 line 68 + 6 bytes
QTTEST! (00401802)
QTTEST! 00401 a26 ()
QTTEST! 00401 b06 ()
QTCORED4! 6 a20611c ()
QTCORED4! 6 a216ab8 ()
QTGUID4! 69580 b38 ()
QTGUID4! 692 ee953 ()
QTGUID4! 692 ee8d1 ()
QTGUID4! 692 efd7d ()
QTGUID4! 68 fb6ad8 ()
QTGUID4! 692 efc08 ()
QTGUID4! 6938 e9e2 ()
QTGUID4! 68 f6bd88 ()
QTGUID4! 68 f69fd1 ()
QTCORED4! 6 a201664 ()
QTGUID4! 695 e8182 ()
QTGUID4! 68 f687e0 ()
QTGUID4! 68 fd3637 ()
QTGUID4! 68 fce482 ()
754962 fa ()
75496 d3a ()
754977 c4 ()
7549788 (a)
QTCORED4! 6 a225e76 ()
QTGUID4! 68 fccf40 ()
QTCORED4! 6 a1ff672 ()
QTCORED4! 6 a1ff79a ()
QTCORED4! 6 a201c94 ()
QTGUID4! 68 f69324 ()
QTTEST! (00401400)
QTTEST! 00401 f32 ()
QTTEST! 00401 c58 ()
QTTEST! 0040124 (b)
QTTEST! 004012 b8 ()
KERNEL32! 751 f336a ()
NTDLL! 770 c9902 ()
NTDLL! 770 c98d5 ()
Still feeling overwhelmed
nullnull