1

For my current project, I needed to convert from String^ to std::string and vice-versa a lot. I read I could accomplish that by marshaling (from what I've read it's a process of conversion between native and managed data types because they are handled differently in the memory).

I read the instructions off of this topic. I put the code in a button event. Since I'm a beginner, I didn't really know which file do I need to include <msclr\marshal_cppstd.h> in. After reading pre-made descriptions in each of the files, I included the library in stdafx.h, which produced the following errors:

error C2065: 'marshal_as' : undeclared identifier
error C2275: 'std::string' : illegal use of this type as an expression

When including it in the main .cpp and stdafx.cpp files, one of the errors I get is:

error C2872: 'IServiceProvider' : ambiguous symbol

even though I included the file before any "using" directive, as advised here.


Thanks in advance.

Community
  • 1
  • 1
0lt
  • 283
  • 2
  • 13
  • It lives in the msclr namespace. Don't put this in your precompiled header, you need to keep lossy string conversions isolated so you'll minimize the damage. – Hans Passant Apr 13 '15 at 16:05
  • Where do I include it then? – 0lt Apr 13 '15 at 16:10
  • 1
    In the .cpp file where you put this string conversion code. Do try to keep it to just one file, very important when you eventually fix the bugs. You eventually will. – Hans Passant Apr 13 '15 at 16:20
  • My string conversion code is a part of a button event, that is in the **Form1.h file**. I tried including both before after #pragma once and both times I get error C2872. – 0lt Apr 13 '15 at 16:33
  • 1
    The full declaration for marshal_as is: msclr::interop::marshal_as – Damian Dixon Sep 20 '17 at 07:46

0 Answers0