Convert String^ in c# to CString in c++/CLI

后端 未结 2 1770
南方客
南方客 2020-12-02 01:53

I need a help on one question where I stuck while coding my app in MFC.

I am using CLR i.e Common Language Runtime in my appli

2条回答
  •  自闭症患者
    2020-12-02 02:34

    Got My answer. Thanks for your support @Elliot Tereschuk.

    I have gone through some references like

    1. How to: Extend the Marshaling Library
    2. Overview of Marshaling in C++
    3. For CString.Format()

    and

    include header files

    #include 
    #include 
    

    using Library using namespace msclr::interop;

    And finally My source code is.

    String^ csPass = gcnew String(strPassword.GetBuffer());
    array^ Value = Encoding::UTF8->GetBytes(csPass);
    for (int i = 0; i < Value->Length; i++ )
    {
    csPass += String::Format( "{0:X2}", Value[ i ] );
    }
    
    marshal_context^ context = gcnew marshal_context();
    
    const char* str = context->marshal_as(csPass);
    
    csMyPass.Format(str);
    

    csMypass is a CString type Variable. Thank you for support.

提交回复
热议问题