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. calling managed function from unmanged class

calling managed function from unmanged class

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++help
2 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.
  • 3 Offline
    3 Offline
    3green
    wrote on last edited by
    #1

    Have been trying without success to call an managed function from within an unmanaged class. This would seem to be a basic requirement, of the dotnet so I am obviously doing something wrong. Given the class CMyManaged header as: #pragma once public __gc class CMyManaged { public: CMyManaged(void); ~CMyManaged(void); void MyFun(void); }; and a standard MFC dialog class, I wish to call MyFun() from within MyMFCDlg(). Now I went about this by declaring a CMyManaged variable m_MyManaged; in the unmanaged MyMFCDlg() header file. Then in MyMFCDlg.OnInitDialog() I try to call m_MyManaged.MyFun(); Have tried declaring the managed variable as gcroot m_MyManaged; But various means to call MyFun() have all resulted in compilation errors. Any help would be appreciated, as the C# dialog box is to limited I need to continue developing partially in Unmanaged C++. Many thanks

    P 1 Reply Last reply
    0
    • 3 3green

      Have been trying without success to call an managed function from within an unmanaged class. This would seem to be a basic requirement, of the dotnet so I am obviously doing something wrong. Given the class CMyManaged header as: #pragma once public __gc class CMyManaged { public: CMyManaged(void); ~CMyManaged(void); void MyFun(void); }; and a standard MFC dialog class, I wish to call MyFun() from within MyMFCDlg(). Now I went about this by declaring a CMyManaged variable m_MyManaged; in the unmanaged MyMFCDlg() header file. Then in MyMFCDlg.OnInitDialog() I try to call m_MyManaged.MyFun(); Have tried declaring the managed variable as gcroot m_MyManaged; But various means to call MyFun() have all resulted in compilation errors. Any help would be appreciated, as the C# dialog box is to limited I need to continue developing partially in Unmanaged C++. Many thanks

      P Offline
      P Offline
      palbano
      wrote on last edited by
      #2

      3green wrote: have all resulted in compilation errors. Post the compiler error messages, otherwise we have to guess. Obvious things to check: Do you have properly configured "mixed mode" project settings? Do you have required #include and import statements? If you don't know what one or both of those are you need to use MSDN to read about "mixed mode" development.

      "No matter where you go, there your are." - Buckaroo Banzai

      -pete

      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