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 4626980
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:30:01+00:00 2026-05-22T03:30:01+00:00

I have a fairly old unmanaged C++ program that called managed c# code (vs2003)

  • 0

I have a fairly old unmanaged C++ program that called managed c# code (vs2003) that I need to convert. (the original c# code was written in .NET1.1, and needed to be recompiled, it was compiled into 4.0) While ultimately I need to have the entire thing re-written, I was hoping to get the original code to run a little longer.

I have boiled the issue that I am seeing down into this test case:

Using VS2010 I created a new project: “Visual C++ | MFC Application”

Using the wizard I then created a dialog based application with all of the default settings.
After including the following header in the app class,

#include <fstream>

in the InitInstance of the new App Class I created a file with the following two lines of code:

ofstream xmlstream;
xmlstream.open("junk.txt");

When the app runs the dialog creates a new file in both Debug and Release mode

However, when I try to enable the c# code by changing the project properties|general|common runtime Support flag to Common Runtime support, old syntax (/clr:oldSyntax) I get the following error.
In Debug mode the program runs just fine, and creates a file.
In Release mode the program crashes executing the line

ofstream xmlstream;

with the error:

An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

The only other reference to issues with this type of program suggested setting the properties for “C/C++|Code Generation|Enable C++ Exceptions” to /EHa which I have done.

I did check for reference to fstream.h instead of fstream (the old style headers no longer exist in 2010, they did in 2003) however I am using the new ones. Unless there is someting wrong with the syntax of declaring a stream object now, I am not sure what is wrong.

Is there another switch that I need to set to make this compile correctly, or am I inherently doing something that does not make sense?

  • 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-22T03:30:02+00:00Added an answer on May 22, 2026 at 3:30 am

    If I’m not wrong VS has continued shipping with a ‘legacy’ iostreams library (the pre-standard version from Dinkumware). (reference) I’m not sure whether VS2003 still included it, but knowing Microsoft, I wouldn’t be surprised.

    It might still be in use and not be compatible with the new C++ standard library containers/ABI. So, I’d check headers and namespace usings to look for

    #include <iostream.h>
    

    fixing to

    #include <iostream>
    

    The link above has some very good guidance on how to migrate any old-style iostreams code to the new style, so I’ll repeat the link: http://members.gamedev.net/sicrane/articles/iostream.html

    HTH

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

Sidebar

Related Questions

I have some fairly old code that runs just fine in Excel versions before
I have a fairly simple const struct in some C code that simply holds
I have a fairly small MySQL database (a Textpattern install) on a server that
I have a fairly standards compliant XHTML+CSS site that looks great on all browsers
I have a fairly large codebase that depends on MooTools v1.11 and am about
I'm currently working with a fairly old product that's been saddled with a lot
I have a fairly old project in vb6. And when I am trying to
I came across a fairly old Java web application that made use of servlets
I have a fairly simple desktop application that uses a .NET setup project (.msi
We have fairly large C++ application which is composed of about 60 projects in

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.