problem using MFC in clr

M

ma

Hello;

I want to use some classes that I wrote (MFC based) in my .net
application. I did the following steps to achieve this:



1- I create a winform application. (The program compile and run
successfully).

2- I changed project setting as documented by MS:
(http://msdn2.microsoft.com/en-us/library/ms235211.aspx ) (The program
compile and run successfully).

3- I add the following line to stdafx.h

#include <afxwin.h> // MFC core and standard components



At this point, the program compiles but when I am trying to run it, I am
getting a heap error. The error message is assertion failed at line 1414 in
file dbgheap.c





What is the problem and how can I solve it?



Best regards
 
M

Marcus Heege

Hi ma,
ma said:
Hello;

I want to use some classes that I wrote (MFC based) in my .net
application. I did the following steps to achieve this:



1- I create a winform application. (The program compile and run
successfully).

2- I changed project setting as documented by MS:
(http://msdn2.microsoft.com/en-us/library/ms235211.aspx ) (The program
compile and run successfully).

3- I add the following line to stdafx.h

#include <afxwin.h> // MFC core and standard components



At this point, the program compiles but when I am trying to run it, I am
getting a heap error. The error message is assertion failed at line 1414
in file dbgheap.c

What is the problem and how can I solve it?

Best regards

I had similar problems in the beta phases of VC2005. My feeling was that
these problems were solved with the VC release, but I can reproduce the bug,
so it seems isn't.

From what I can see so far, this might be a bug in the CRT initialization
code. It seems that DLL and EXE initialization is confused for some reason I
don't know yet.

I try to find out something more about it and let you know.

Marcus Heege
 
J

Jochen Kalmbach [MVP]

Hi ma!
I want to use some classes that I wrote (MFC based) in my .net
application. I did the following steps to achieve this:

1- I create a winform application. (The program compile and run
successfully).

2- I changed project setting as documented by MS:
(http://msdn2.microsoft.com/en-us/library/ms235211.aspx ) (The program
compile and run successfully).

3- I add the following line to stdafx.h

#include <afxwin.h> // MFC core and standard components

You should report this bug at
http://lab.msdn.microsoft.com/productfeedback/

And post the link to your bug-report here, so we can vote for it!

Greetings
Jochen
 
J

Jochen Kalmbach [MVP]

Hi ma!

It seems that this bug should have been fixed in the RTM...
See also:

atlstr.h and /clr
http://lab.msdn.microsoft.com/produ...edbackid=6f3a7717-3d9a-473d-ba0e-e0a40ba72821

An error arises at launching if an ATL header is included in the Managed
C++/CLI application project.
http://lab.msdn.microsoft.com/produ...edbackID=2fe20dc8-3317-433e-9a2b-739aae0855a5

Greetings
Jochen
 
J

Jochen Kalmbach [MVP]

Hi ma!

There is a work-around for this problem:

1. Change the "entry point" in you linker settings from "main" to
"wWinMainCRTStartup"
2. Add "#include <afxwin.h>" to your "stdafx.h"
3. Replace your "main" method with the following:
class CMFCApp : public CWinApp
{
public:
virtual BOOL InitInstance()
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return FALSE;
}
} theApp;



See also: FDBK47757#1: Replace "main" with CWinApp
http://lab.msdn.microsoft.com/ProductFeedback/ViewWorkaround.aspx?FeedbackID=FDBK47757#1

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top