0
votes

I am trying to create a mixed mode (managed and unmanaged) C++ DLL with CLR option and I require the use of AFX library. So I included "afxwin.h" in a file (which uses GL/gl.h). However I run into compile errors no matter what I do and I have tried every option in the project settings to fix them, but no use.

A. When I compile with CLR option I see this error (when it compiles the file which includes afwin.h):

1>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\afx.h(24): fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

B. When I compile with _AFXDLL defined in stdafx.cpp or enabling "Use MFC in a shared DLL", to address the error in A, I see these and whole bunch of other errors in the same file:

1> _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h) 1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(46): error C2059: syntax error : '-' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(60): error C2143: syntax error : missing ';' before '}' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(60): error C2238: unexpected token(s) preceding ';' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(61): error C2059: syntax error : 'public' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(65): error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(65): error C2589: '-' : illegal token on right side of '::' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(65): error C2059: syntax error : '::' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(67): error C2143: syntax error : missing ';' before '{'

Any ideas on how to fix this issue? I am using VS 2010.

1

1 Answers

0
votes

Changing the MFC option afterwards to "Use MFC in a shared DLL" is not that straightforward, there are other options you may need to change.

The easiest way is to create a new dummy MFC project with the wizard and compare the project properties of the two projects.

Re CLR, what works for me is to place all managed C++ code in one or two sources and turn on /CLR only for those sources instead of the whole project.