4

I have this monstrous C++ application built using MFC(mainly) and COM. It links to several libraries and does a lot of scientific computing. So, now I want to add some new features to it and as an organizational policy, we are developing everything new using .NET. So, this new UI feature is going to be built using WPF and will be consumed in this existing C++ application.

I know how to use a WPF control in a C++ application, so that's not the problem. The problem is that when I try to turn on CLR on this project, it takes a lot of time (around 10 minutes) in linking stage to perform the linking and produce a mixed mode executable. In the end, it manages to do so and successfully creates the executable. But the problem is that whenever I launch this executable, it crashes. I tried to debug InitInstance but it crashes somewhere before this. I am a little stumped on what to try next.

Does anybody have any idea what might be the cause of this.

The target framework of the mixed mode assembly is 4.0 (as it should be) so THIS is not the problem here.

FYI, ILDasm fails to load this exe as well. It takes a lot of time, gives no error but it doesn't load it either. This gives me the impression that somehow managed image is not created properly.

Muhammad Hasan Khan
  • 34,648
  • 16
  • 88
  • 131
Aamir
  • 14,882
  • 6
  • 45
  • 69
  • Try this first on a small sample MFC app. Use Debug + Exceptions, Thrown checkbox. – Hans Passant Jul 09 '12 at 13:28
  • Since you're able to compile the C++ app, what sort of error or feedback do you get when you run in debug mode? Does the IDE crash as well? There's a debug mode option in the project settings to select Native, or Managed or both debugging. Try each combination and see what type of info you can get out it. What type of crash is it? Does the app simply not start up? Do you get a dialog indicating unhandled exception? If so, specifically what does that dialog say? – Tra5is Jul 09 '12 at 22:33

1 Answers1

0

Not sure if this is necessary, but it doesn't hurt either. New MFC projects have this in the constructor of your CWinApp-derived class:

#ifdef _MANAGED
    // If the application is built using Common Language Runtime support (/clr):
    //     1) This additional setting is needed for Restart Manager support to work properly.
    //     2) In your project, you must add a reference to System.Windows.Forms in order to build.
    System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException);
#endif
l33t
  • 18,692
  • 16
  • 103
  • 180