views:

287

answers:

1

Summary:

When attempting to use marshalling to pass string data into a C++ DLL from C#, I'm getting

'msclr::interop::error_reporting_helper<_To_Type,_From_Type>::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\microsoft visual studio 9.0\vc\include\msclr\marshal.h 203

I'm using Visual Studio 2008 Professional Edition; Visual C++ 2008; .Net 3.5.

Detail:

The method concerned (in its simplest form) is as follows:

LibDSSDLL::DssOutputSocketFacade::DssOutputSocketFacade(const System::String^ name)
{
    marshal_context^ context = gcnew marshal_context();
    std::string n = context->marshal_as<std::string>(name);

    this->socket = new DssOutputSocket( n);
}

The header includes in the order they are presented to the preprocessor are

#include "StdAfx.h"
#include <string>
#include <iostream>
#include <msclr\marshal_cppstd.h>

#using <mscorlib.dll>
using namespace System;
using namespace msclr::interop;

This looks to me as though it conforms to the example cited here and to the documentation at MSDN (Stack Overflow is refusing to let me cite a second URL); however clearly the C++ compiler is not finding the conversion it needs.

What have I missed? I confess I'm not very expert with C++ or with Windows.

A: 

The documentation does not say it takes a const String^. Remove the const.

Sheng Jiang 蒋晟
Thanks, that was the right answer!
Simon Brooke