CString conversion problem while compling with /clr switch

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • npotnis
    New Member
    • Aug 2006
    • 1

    #1

    CString conversion problem while compling with /clr switch

    Hi All,

    I am trying to compile an existing C++ unamanaged application with the /clr switch in VS.Net 2003, as I need to use managed extensions in the code.

    In a cpp file I have the following code :

    CString strRet;
    COleVariant var = m_pRSTFormList->GetFieldValue( "FormName") ;
    if(var.vt == VT_BSTR)
    strRet = var.pbVal;


    However the compiler gives the following error -

    error C2664: 'PtrToStringCha rs' : cannot convert parameter 1 from 'BYTE *' to 'const System::String __gc *'
    Conversion from 'void*' to pointer to non-'void' requires an explicit cast
    BrowserDatabase .cpp(223) : see reference to function template instantiation 'ATL::CStringT< BaseType,String Traits>::CStrin gT<BYTE>(System String *)' being compiled
    with
    [
    BaseType=char,
    StringTraits=St rTraitMFC_DLL<c har>,
    SystemString=BY TE
    ]


    I got to know that CString has a constructor that takes System::String * parameter. However in this case I have a Byte *. Any form of casting like
    strRet = (Cstring) var.pbVal;
    strRet = (System::String *) var.pbVal or even a static_cast does not seem to work.

    Your help would be highly appreciated.
    Thanks in advance,
    Niranjan.
Working...