Tuesday, August 04, 2009

Converting CString to CComBSTR

Code below shows how to convert CString to CComBSTR.
// CComBSTR.cpp : Defines the entry point for the console application.

#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
 CComBSTR szDbgMsg;
 CString sMsg;
 sMsg = _T("Hello world new");
 sMsg.Format(_T("%s : %d"), sMsg, 12);
 //szDbgMsg = L"Hello world ";
 szDbgMsg = sMsg.GetBuffer();
 CW2A printstr(szDbgMsg);
 std::wcout << ((CString)szDbgMsg).GetBuffer() << std::endl;
 std::wcout << sMsg.GetBuffer() << std::endl;
 return 0;


1 comment:

Anonymous said...

Its like you read my mind! You appear to know a lot about this, like
you wrote the book in it or something. I think that you can do with a few pics to drive the message home a little bit, but instead of that,
this is great blog. A fantastic read. I'll definitely be back.

My website; raspberry ketone diet