المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : VC++ MFC class data member initialisation [modified]



C++ Programming
09-08-2009, 04:30 PM
I am learning to use VS2005 creating a VC++ MFC project to unterface to serial ports. I am in the initial stages of getting to grips with creating a serial port class. I am finding a few problems along the way with vartiable / data member initialisation.


CGCSerial h-file

int CharCount;
int CharCount2;
int CharCountThree;
CString TxString;
size_t InputStringLength;
TCHAR * pStr;
char * pOutputString;


cpp-file(s)

CMyDrawView::OnToolWrite2SerialPort
//member function called by clicking on windows menu item
{
CGCSerial *pGcSp = new CGCSerial(_T("12345")); //create instance of CGCSerial class
pGcSp -> GCTx; //call transmit member function
delete pGcSp; //cleanup
}


CGCSerial::GCSerial(TxString)
{
//constructor
CharCount2 = 0
CharCountThree = 0;
}

CGCSerial::~GCSerial
{
//destructor
}

CGCSerial::GCTx
{
InputStringLength = wcslen(TxString); //measuring length of incoming string
CharCountThree = sizeof(InputStringLength); //load CharCount3 with something
TempString.Format(_T("executing function CGCSerial::GCTx"));
AfxMessageBox(TempString);

pStr = TxString.GetBuffer(256);
CharCount2 = sizeof(pStr);
TxString.ReleaseBuffer;

InputStringLength = wcslen(pStr); //measuring length of

CharCount2 = 0x2345; // ###
CharCountThree = 0x5678; //###

CharCount2 = sizeof(TxString);
CharCountThree = sizeof(pOutputString);

pOutputString = CW2A(TxString); //convert wide string to ANSI string
...
...

}


My problem is that I admit this code doesn't look the most useful and is due to getting to grips with VC++ functions. The lines marked with ### don't seem to get executed! If I use the debugger, the debugger stops at these lines but upon viewing these data member's they do not get loaded with 0x2345 & 0x5678 respectively??? Is this a compiler bug??

any help would be greatly appreciated http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif

modified on Tuesday, September 8, 2009 8:21 AM