0

我正在尝试使用 CLR 选项创建混合模式(托管和非托管)C++ DLL,并且我需要使用 AFX 库。所以我在一个文件(使用 GL/gl.h)中包含了“afxwin.h”。但是,无论我做什么,我都会遇到编译错误,并且我已经尝试了项目设置中的每个选项来修复它们,但没有用。

A. 当我使用 CLR 选项编译时,我看到了这个错误(当它编译包含 afwin.h 的文件时):

1>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\afx.h(24): 致命错误 C1189: #error : Building MFC application with /MD[d] (CRT dll version)需要 MFC 共享 dll 版本。请#define _AFXDLL 或不要使用 /MD[d]

B. 当我使用在 stdafx.cpp 中定义的 _AFXDLL 进行编译或启用“在共享 DLL 中使用 MFC”以解决 A 中的错误时,我在同一个文件中看到了这些错误和一大堆其他错误:

1> _WIN32_WINNT 未定义。默认为 _WIN32_WINNT_MAXVER(参见 WinSDKVer.h) 1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(46):错误 C2059:语法错误:'-' 1>c :\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(60): error C2143: syntax error: missing ';' 在 '}' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(60) 之前:错误 C2238:在 ';' 之前出现意外令牌 1>c:\program 文件 (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(61): 错误 C2059: 语法错误: 'public' 1>c:\program files (x86)\microsoft Visual Studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(65):错误 C2059:语法错误:')' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(65): error C2589: '-' : '::' 右侧的非法标记 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):错误 C2143:语法错误:缺少 ';' 前 '{' \program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(67): error C2143: syntax error: missing ';' 前 '{' \program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxanimationcontroller.h(67): error C2143: syntax error: missing ';' 前 '{'

有关如何解决此问题的任何想法?我正在使用 VS 2010。

4

1 回答 1

0

之后将 MFC 选项更改为“在共享 DLL 中使用 MFC”并不是那么简单,您可能需要更改其他选项。

最简单的方法是使用向导创建一个新的虚拟 MFC 项目并比较两个项目的项目属性。

关于 CLR,对我有用的是将所有托管 C++ 代码放在一个或两个源中,并仅为这些源而不是整个项目打开 /CLR。

于 2014-03-26T08:39:30.643 回答