mfc - Use a C++/CLI DLL using afxwinforms.h as Reference of another C++/CLI DLL also using afxwinforms.h -
in visual c++ 2010 added reference c++/cli dll (controlwrapper.dll) c++/cli dll (clilibrary.dll).
both including afxwinforms.h in stdafx.h.
when try compile these errors:
error c2011: 'microsoft::visualc::mfc::cwin32window' : 'class' type redefinition error c2011: 'microsoft::visualc::mfc::cwinformseventshelper' : 'class' type redefinition
if turn of option reference assembly output , add #using "clilibrary.dll"
using .cpp file following warnings:
1>controlwrapper.dll : warning c4944: 'cwin32window' : cannot import symbol 'c:\dev\trunk\clilibrary.dll': 'microsoft::visualc::mfc::cwin32window' exists in current scope 1> c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxwinforms.h(83) : see declaration of 'microsoft::visualc::mfc::cwin32window' 1> diagnostic occurred while importing type 'microsoft.visualc.mfc.cwin32window' assembly 'clilibrary, version=1.0.4843.17337, culture=neutral, publickeytoken=null'. 1>controlwrapper.dll : warning c4944: 'cwinformseventshelper' : cannot import symbol 'c:\dev\sfirm\trunk\sfclrlib\debug\sfclrlib.dll': 'microsoft::visualc::mfc::cwinformseventshelper' exists in current scope 1> c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxwinforms.h(122) : see declaration of 'microsoft::visualc::mfc::cwinformseventshelper' 1> diagnostic occurred while importing type 'microsoft.visualc.mfc.cwinformseventshelper' assembly 'clilibrary, version=1.0.4843.17337, culture=neutral, publickeytoken=null'.
how solve error?
well, painful problem. explains why first programmer ever encountered uses this. problem caused declaration in afxwinforms.h:
public ref class cwin32window : public system::windows::forms::iwin32window // etc..
the public keyword killer, adds class manifest of assembly. when reference in project includes header there 2 definitions of class. mix of both native , managed classes in header prevents clean solution.
i think found best solution, using #include, #pragma comment(disable:4944) shutup compiler. including header inside namespace might viable hack, renames namespace of cwin32window, i'd expect trouble when linking mfcm90.lib. restructuring solution , keeping winforms code inside 1 project thing can recommend.
Comments
Post a Comment