+ Reply to Thread
Results 1 to 2 of 2

Thread: How to convert BSTR to CString and vice-versa?

  1. #1

    How to convert BSTR to CString and vice-versa?

    How to convert BSTR to CString and vice-versa?

  2. #2
    Example:

    Code:
    void UseCStringAndBSTR()
    {
    	//#include <comutil.h>
    	//PART 1 : CString to BSTR
    	CString strHello = "Hello World!!!" ;
    
    	BSTR bstrHello = strHello.AllocSysString() ;
    
    	//PART 2 : BSTR to CString
    	CString strHelloFromBSTR(_com_util::ConvertBSTRToString(bstrHello)) ;
    
    
    	//PART 2 : BSTR to char */char []
    	char szHello[100] ;
    	sprintf(szHello, "%s", (LPCTSTR) _com_util::ConvertBSTRToString(bstrHello)) ;
    
    	::SysFreeString(bstrHello) ;
    }

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts