.netstringc++-climarshallingmixed-mode

marshal String^ to string. Get an error with marshal.h


I have both of these in my class

#include <msclr/marshal.h>
#include <msclr/marshal_cppstd.h>

and I have

using namespace msclr::interop;

I am using it to marshal String^ to string. Here is one example.

string ProgReleaseType = marshal_as<std::string>(CurrentSubKey->GetValue("ReleaseType", NULL)->ToString());

When I build, I get this error.

Error   53  error C4996: msclr::interop::error_reporting_helper<_To_Type,_From_Type,false>::marshal_as': This conversion is not supported by the library or the header file needed for this conversion is not included.  Please refer to the documentation on 'How to: Extend the Marshaling Library' for adding your own marshaling method.    C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\msclr\marshal.h  237

When I go into the marshal.h and read through line 237 is says to please use a marshal_context. I thought I was. I don't get what it doesn't like.


Solution

  • Use a marshal context:

     msclr::interop::marshal_context context;
    
    string ProgReleaseType = context.marshal_as<std::string>(CurrentSubKey->GetValue("ReleaseType", NULL)->ToString());