Accessing the DCB object
-
i have a public DCB variable(DCB m_dcb) in a class called Comm which is in Comm.h file. In Comm.cpp am accessing the m_dcb through a member function. this member function i am calling from the App file. Its compliling & linking. But whrn u go in debug mode or run the appliaction,the member function not able to recognize the DCB variable and throws the error "(MSVCRTD.DLL)0xC0000005:Access violation" at the "FillMemory(&dcb, sizeof(dcb),0);" line. My code is as follows. ///////////////Comm.h/////////////////////////////////// class Comm { private: BOOL OpenComm(CString strPort); BOOL SetComTimeOuts(); BOOL SetComState(); public: Comm(CString port = "COM1"); virtual ~Comm(); BOOL Connect(CString sPort); BOOL Disconnect(); BOOL ChangeBaudRate(DWORD dwBaudrate); private: CString m_strPort; BYTE* m_pMsgBuf; public: static HANDLE m_hComEvent; static HANDLE m_hCommHandle; DCB dcb; OVERLAPPED osReader; OVERLAPPED osWrite; BOOL fWaitingOnRead; BOOL fWaitingOnWrite; }; //////////////Comm.cpp//////////////////////// #include "stdafx.h" #include "CEU Simulator.h" #include "Comm.h" BOOL Comm::Connect(CString strPort) { if(OpenComm(strPort)) if(PurgeComm(m_hCommHandle, PURGE_RXCLEAR | PURGE_TXCLEAR)) return TRUE; return FALSE; } //opencomm BOOL Comm::OpenComm(CString strPort) { m_hCommHandle = ::CreateFile( strPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL ); if (m_hCommHandle == INVALID_HANDLE_VALUE) { return FALSE; } /*if(INVALID_HANDLE_VALUE == m_Handle && ERROR_ALREADY_EXISTS != GetLastError()) return FALSE;*/ if( !SetComTimeOuts() ) { CloseHandle(m_hCommHandle); m_hCommHandle = INVALID_HANDLE_VALUE; return FALSE; } if( !SetComState() ) { CloseHandle(m_hCommHandle); m_hCommHandle = INVALID_HANDLE_VALUE; return FALSE; } return TRUE; } // setcommtimeouts BOOL Comm::SetComTimeOuts() { COMMTIMEOUTS commTimeOut; commTimeOut.ReadIntervalTimeout = MAXDWORD; // | Read operation should return immediately commTimeOut.ReadTotalTimeoutMultiplier = 0; // |=> with chars that have been revceived, even commTimeOut.ReadTotalTimeoutConstant = 0; // | even no chars have been received commTimeOut.WriteTotalTimeoutMultiplier = 2; commTimeOut.WriteTotalTimeoutConstant = 0; if( !SetCommT