Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Using MFC with windows form

Using MFC with windows form

Scheduled Pinned Locked Moved Managed C++/CLI
helpc++comdata-structuresdebugging
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    minihotto
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • M minihotto

      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

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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:

      M 1 Reply Last reply
      0
      • M Mark Salsbery

        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:

        M Offline
        M Offline
        minihotto
        wrote on last edited by
        #3

        yes, I only need the message map in MFC. I want to use MFC in windows form application, not use windows form controls in MFC. Appreciate ur reply. Thx. jane -- modified at 0:46 Monday 12th November, 2007

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups