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. CWinFormsControl Problem

CWinFormsControl Problem

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++dotnethelp
5 Posts 3 Posters 1 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.
  • A Offline
    A Offline
    Aamir Butt
    wrote on last edited by
    #1

    I have a .NET Control which I want to host in a CDialog. It's quite easy by including afxwinforms.h and having a member variable like this: CWinFormsControl m_myControl But the problem is that if I do something like this I have to include afxwinforms.h in my header file. I am including this header file in other classes and I dont want to enable clr for those classes. Is there any workaround to this. I have tried something like having a CWnd* as a member variable and casting it to CWinFormsControl in .cpp but type-casting for CWinFormsControl doesnt work. "Writing specifications is like writing a novel. Writing code is like writing poetry."

    N 1 Reply Last reply
    0
    • A Aamir Butt

      I have a .NET Control which I want to host in a CDialog. It's quite easy by including afxwinforms.h and having a member variable like this: CWinFormsControl m_myControl But the problem is that if I do something like this I have to include afxwinforms.h in my header file. I am including this header file in other classes and I dont want to enable clr for those classes. Is there any workaround to this. I have tried something like having a CWnd* as a member variable and casting it to CWinFormsControl in .cpp but type-casting for CWinFormsControl doesnt work. "Writing specifications is like writing a novel. Writing code is like writing poetry."

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      Aamir Butt wrote:

      I have a .NET Control which I want to host in a CDialog. It's quite easy by including afxwinforms.h and having a member variable like this: CWinFormsControl m_myControl But the problem is that if I do something like this I have to include afxwinforms.h in my header file. I am including this header file in other classes and I dont want to enable clr for those classes. Is there any workaround to this. I have tried something like having a CWnd* as a member variable and casting it to CWinFormsControl in .cpp but type-casting for CWinFormsControl doesnt work.

      You could try a #ifdef _MANAGED block to declare the CWinFormsControl member.

      Regards, Nish


      Nish's thoughts on MFC, C++/CLI and .NET (my blog)
      Currently working on C++/CLI in Action for Manning Publications.

      G 1 Reply Last reply
      0
      • N Nish Nishant

        Aamir Butt wrote:

        I have a .NET Control which I want to host in a CDialog. It's quite easy by including afxwinforms.h and having a member variable like this: CWinFormsControl m_myControl But the problem is that if I do something like this I have to include afxwinforms.h in my header file. I am including this header file in other classes and I dont want to enable clr for those classes. Is there any workaround to this. I have tried something like having a CWnd* as a member variable and casting it to CWinFormsControl in .cpp but type-casting for CWinFormsControl doesnt work.

        You could try a #ifdef _MANAGED block to declare the CWinFormsControl member.

        Regards, Nish


        Nish's thoughts on MFC, C++/CLI and .NET (my blog)
        Currently working on C++/CLI in Action for Manning Publications.

        G Offline
        G Offline
        georgeraafat
        wrote on last edited by
        #3

        Wouldn't that change the class layout depending on who's including it? For example, if I include the header in a .cpp that is compiled native, the class layout does not contain the managed memeber. If I include the header in a .cpp that is compiled /clr, the class layout contains the managed memeber... This means they are essentially two different classes with the same name... The linker should emit an error in that scenario and not allow it... I haven't tried it though, so I might be wrong. gmileka

        N 1 Reply Last reply
        0
        • G georgeraafat

          Wouldn't that change the class layout depending on who's including it? For example, if I include the header in a .cpp that is compiled native, the class layout does not contain the managed memeber. If I include the header in a .cpp that is compiled /clr, the class layout contains the managed memeber... This means they are essentially two different classes with the same name... The linker should emit an error in that scenario and not allow it... I haven't tried it though, so I might be wrong. gmileka

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          georgeraafat wrote:

          Wouldn't that change the class layout depending on who's including it?

          Yes, it would. A workaround would be to use a CWinFormsControl* member if it's managed compilation, and a dummy void* if it's unmanaged compilation. Thus the class layout is unchanged. Regards, Nish


          Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
          Currently working on C++/CLI in Action for Manning Publications.

          A 1 Reply Last reply
          0
          • N Nish Nishant

            georgeraafat wrote:

            Wouldn't that change the class layout depending on who's including it?

            Yes, it would. A workaround would be to use a CWinFormsControl* member if it's managed compilation, and a dummy void* if it's unmanaged compilation. Thus the class layout is unchanged. Regards, Nish


            Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
            Currently working on C++/CLI in Action for Manning Publications.

            A Offline
            A Offline
            Aamir Butt
            wrote on last edited by
            #5

            Yes, this one looks good. Let me try it and then I will let you know if it works or not. Thanks for the reply. "Writing specifications is like writing a novel. Writing code is like writing poetry."

            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