Using MFC with windows form
-
I create a windows form application named p2pport. and I want to use the Message Map of MFC. so I use MFC with shared DLL and include afxwin.h. But When I compile it, it says that Debug Assertion Failed File : dbgheap.c line 144 Expression : _CrtIsValidHeapPointer(pUserData) I find it is because of the afxwin.h. I google it and found that it is a bug that was reported to MSDN. http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99715[^][^]I use that method to replace the main function and put #include in stdfax.h file. My original code is
#include "stdafx.h" #include "Dlg.h" using namespace p2pport; [STAThreadAttribute] int main(void)//array ^args) { // 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 Dlg()); //Application::Run(gcnew Form2()); CMFCApp k; return 0; }
And I modify it.#include "stdafx.h" #include "Dlg.h" using namespace p2pport; [STAThreadAttribute] 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 Dlg()); return FALSE; } }theApp;
But it comes the error. error C3115: 'System::STAThreadAttribute': this attribute is not allowed on 'theApp' I delete the[STAThreadAttribute].
It comes another two errors. error LNK2001: unresolved external symbol _main fatal error LNK1120: 1 unresolved externals I dont know how to solve it. I stuck it all day. Can anybody help me to solve the problem. Appreciate for ur reply Thx. Jane -
I create a windows form application named p2pport. and I want to use the Message Map of MFC. so I use MFC with shared DLL and include afxwin.h. But When I compile it, it says that Debug Assertion Failed File : dbgheap.c line 144 Expression : _CrtIsValidHeapPointer(pUserData) I find it is because of the afxwin.h. I google it and found that it is a bug that was reported to MSDN. http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99715[^][^]I use that method to replace the main function and put #include in stdfax.h file. My original code is
#include "stdafx.h" #include "Dlg.h" using namespace p2pport; [STAThreadAttribute] int main(void)//array ^args) { // 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 Dlg()); //Application::Run(gcnew Form2()); CMFCApp k; return 0; }
And I modify it.#include "stdafx.h" #include "Dlg.h" using namespace p2pport; [STAThreadAttribute] 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 Dlg()); return FALSE; } }theApp;
But it comes the error. error C3115: 'System::STAThreadAttribute': this attribute is not allowed on 'theApp' I delete the[STAThreadAttribute].
It comes another two errors. error LNK2001: unresolved external symbol _main fatal error LNK1120: 1 unresolved externals I dont know how to solve it. I stuck it all day. Can anybody help me to solve the problem. Appreciate for ur reply Thx. JaneThere's no Microsoft bug involved here. If you're going to mix MFC and CLR, you need to make sure the proper initialization of the CRT and MFC is done. You also have to think about how Windows messages are going to be processed. You may want to study the "Using Windows Forms in MFC" section here: Interop (How Do I in Visual C++)[^] Is the only reason you're using MFC is to be able to use the message map? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
There's no Microsoft bug involved here. If you're going to mix MFC and CLR, you need to make sure the proper initialization of the CRT and MFC is done. You also have to think about how Windows messages are going to be processed. You may want to study the "Using Windows Forms in MFC" section here: Interop (How Do I in Visual C++)[^] Is the only reason you're using MFC is to be able to use the message map? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: