Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1002709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:52:05+00:00 2026-05-16T07:52:05+00:00

So i work in clr, creating .net dll in visual c++. I tru such

  • 0

So i work in clr, creating .net dll in visual c++.

I tru such code:

 static bool InitFile(System::String^ fileName, System::String^ container)
{
    return enc.InitFile(std::string(fileName), std::string(container));
}

having encoder that normaly resives std::string. but here the compiler (visual studio) gives me C2664 error if I strip out arguments from std::string and C2440 which is in general the same. VS tells me that it just can not to convert System::String^ into std::string.

So I am sad… what shall I do to turn System::String^ into std::string?

Update:

Now with your help I have such code

#include <msclr\marshal.h>
#include <stdlib.h>
#include <string.h>
using namespace msclr::interop;
namespace NSSTW
{
  public ref class CFEW
  {
 public:
     CFEW() {}

     static System::String^ echo(System::String^ stringToReturn)
    {
        return stringToReturn;  
    }

     static bool InitFile(System::String^ fileName, System::String^ container)
    {   
        std::string sys_fileName = marshal_as<std::string>(fileName);;
        std::string sys_container = marshal_as<std::string>(container);;
        return enc.InitFile(sys_fileName, sys_container);
    }
...

but when I try to compile it gives me C4996

error C4996: ‘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.

what to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:52:05+00:00Added an answer on May 16, 2026 at 7:52 am

    If you’re using VS2008 or newer, you can do this very simply with the automatic marshaling added to C++. For example, you can convert from System::String^ to std::string via marshal_as:

    System::String^ clrString = "CLR string";
    std::string stdString = marshal_as<std::string>(clrString);
    

    This is the same marshaling used for P/Invoke calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CLR profiler does not seem to work with the Silverlight CLR. Does another memory
If I use /clr:oldSyntax the following should work: public __value enum IceCreamFlavors { Vanilla,
I work in VBA, and want to parse a string eg <PointN xsi:type='typens:PointN' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
I work for a .NET/MSSQL shop that has trouble supporting customers running Novell, partially
I did substantial work developing CLR routines to implement DAL functionality using VS2010 intending
Microsoft .NET CLR is an implementation of CLI standard. However, the last publication of
I am trying to reference a class library from a Visual C# SQL CLR
At work we are currently still using JUnit 3 to run our tests. We
At work we are being asked to create XML files to pass data to
I work with C# at work but dislike how with webforms it spews out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.