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