Archive for May, 2008

I faced one situation during my current project. Want to convert one CString data to CByteArray.. One simple method is as follows.

CByteArray objByteArray;
BYTE *pByteArray = (PBYTE)(LPCTSTR)csData.GetBuffer();
ULONGLONG uLength = csData.GetLength();
ULONGLONG uCapacity = uLength * 2;

DWORD dwDataLength = static_cast(uLength);
memcpy(objByteArray.GetData(), pByteArray, dwDataLength);


Common MFC #defines !

Hope all of them may go through some of the MACROS in MFC..

Here’s some information !!!


_DEBUG — This symbol is set for debug builds and off for release builds.

_AFXDLL–Used to seperate DLL from LIB code.

_UNICODE–Defined if Unicode is build into MFC.




CString to TCHAR

CString is a very useful MFC class for string management. But, sometimes we want to convert CString data to TCHAR or something.

here is one small code snippet for performing this operation. 😉

CString csData(_T(“”));
LPTSTR szData = csData.GetBuffer();
or like this
CString csTemp( "Sample data" );

LPTSTR lpszData = new TCHAR[csTemp.GetLength()+1];

_tcscpy(lpszData , csTemp);

delete[] lpszData;// don't forget to do this.