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

  • Home
  • SEARCH
  • 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 3696950
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:48:03+00:00 2026-05-19T04:48:03+00:00

I’m considering porting an application C / C + + in C + +

  • 0

I’m considering porting an application C / C + + in C + + / CLI.

Mainly I would like to exploit the potential of reflection, XML serialization and in general all the features in. NET framework offered by Microsoft (maybe even in mono).

The project in question does not use the STL heavily, and application objects are mostly allocated statically. A lot of code is written in C, another was implemented in C + +.

The problem is that the code is very, very, very “long”: this is a problem for the time required for the conversion of the existing code so that it runs properly.

I tried to create a C + + project compiled with flag in / clr, was not so bad after all. you can keep your existing code C + +, but in the meantime use the classes “managed”, is even able to access “managed” objects from C + + class methods.

The flaws that I found very few, but make me puzzled about this “migration” …

To take advantage of the data serialization using reflection, all my data structures should be managed. An unmanaged class can not declare fields as defined by a type of managed class. To resolve this problem if a class is converted so that it is managed by the garbage collector, every class that declares a member of that type to be managed as well.

What difficulties may be encountered during the introduction of managed classes?

Well, I’m thinking about:

  • String management (I hate to call AllocaHGlobal to convert System.String to char* each time I need it (for example, as function parameter)
  • Array management (conversion of classical arrays to cli::array)
  • (already mentioned) mixing managed and unmanaged classes
  • exception handling
  • crash (core) dump creation how is affected
  • …any other that I haven’t thought yet…
  • 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-19T04:48:03+00:00Added an answer on May 19, 2026 at 4:48 am

    Unmanaged classes can have managed members. The trick is to use the gcroot template. Look here

    http://weblogs.asp.net/kennykerr/archive/2005/07/12/Mixing-Native-and-Managed-Types-in-C_2B002B00_.aspx

    to learn more about it.

    EDIT: as a response to some of your other questions: when you have a working C++ code base which is so big that you have to expect change requests from production while in parallel you are working on the C++/CLI port, IMHO the best approach is to avoid having two copies of the same code base. Instead, try to make the same code compilable both with C++ and C++/CLI, using #ifdef‘s, macros, generators etc. I know that’s possible since this is exact what we did some time ago when porting a program of ~120.000 lines of code.

    For string conversion, we were using this code:

    typedef System::String^ SysString;
    
    inline SysString Std2Sys(const std::string &s)
    {
        return gcnew System::String(s.c_str());
    }
    
    inline std::string Sys2Std(SysString ss) {
        using namespace System::Runtime::InteropServices;
        const char* chars = 
          (const char*)(Marshal::StringToHGlobalAnsi(ss)).ToPointer();
        std::string s = chars;
        Marshal::FreeHGlobal(System::IntPtr((void*)chars));
        return s;
    }
    

    (performance was never an issue with that in our case, might be different in yours, but don’t try to optimize anything if there is not any need to).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I'm parsing an XML file, the creators of it stuck in a bunch social

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.