Export a subclass of CWinFormsView from MFC extension dll
-
Friday, May 11, 2012 12:20 PM
I'm using CWinFormsView to use a .Net control in an MFC application.
This works OK.
I have some application specific initialization, so I made a subclass of CWinFormsView with the same parameters in the constructor:
CWinFormsView(System::Type^ pManagedViewType);
This works when this class is in the same dll as it is used in.
I want to move this code to a common dll, so that it can be used from different dlls in the application.
Then the problems start. I get the following error message:
__declspec(dllexport) cannot be applied to a function with the __clrcall calling convention
How can I then make this class visible to other dlls?
It must be possible, I'm only trying to do what Microsoft already does itself, export a native class with a managed parameter in the constructor.
Has anybody any ideas on how to do that?
All Replies
-
Monday, May 14, 2012 8:59 AMModerator
Hi Jan,
According to your description, I think you receive Compiler Error C3395. I am sorry to say that you cannot use dllexport on any method that includes a CLR type in its signature. The reason is that dllexport is a purely native construct and there is no way to support passing a CLR type, like System::Type and System::String, through the DLL boundary.
To fix this issue, please try the following recommended methods:
1->Don't use managed parameters or change it to a managed class.
2->Try to use this as a static library instead of a dynamic library.By the way, you can refer to the following links if you want to know more information about this error:
http://msdn.microsoft.com/en-us/library/ze0zzybc.aspx
http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/1f0f5cb9-c476-4d87-b42f-964f1c28bd3b/
http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/e15d6303-876f-4a40-b9c5-f6945517cd23
http://msdn.microsoft.com/en-us/magazine/cc163602.aspxI hope this reply is helpful to you. If you have any questions, please feel free to let me know.
Best regards,Helen Zhao [MSFT]
MSDN Community Support | Feedback to us
- Marked As Answer by Helen ZhaoModerator Thursday, May 17, 2012 9:05 AM

