获取 MIDL 2003 重新定义错误
Posted
技术标签:
【中文标题】获取 MIDL 2003 重新定义错误【英文标题】:Getting MIDL 2003 Redefinition errors 【发布时间】:2019-05-27 04:44:57 【问题描述】:我有一个非常简单的程序,我正在尝试编译它,然后再进一步构建它。我正在尝试学习 COM,因此遵循 here,我在 VS 2017 中创建 app.h
和 app.cpp
文件并使用 ATL 模板。当我尝试构建解决方案时,我收到很多 MIDL 200 重新定义错误。
更新(基于@Roman R. 的回复)请注意,如果我在开发命令行上使用cl /LD app.cpp
,我能够正确生成app.dll
。 MIDL 2003 重新定义错误仅在尝试通过 Visual Studio 构建解决方案时出现。我正在使用 VS 2017 社区版,所以不确定其他版本的 Visual Studio 是否有同样的问题。
我的包含路径简单地继承自父默认值,即标准 $(VC_IncludePath)
和 $(WindowsSDK_IncludePath)
。我的 Windows SDK 版本是 10.0.17763.0,MSVC 版本是 14.16.27023
//app.h
#pragma once
#define STRICT
#ifndef _WINVER
#define _WINVER 0x0A00
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0A00
#endif
#define _USRDLL
#define _ATL_ATTRIBUTES
#define _ATL_APARTMENT_THREADED
#define _ATL_NO_AUTOMATIC_NAMESPACE
#include <SDKDDKVer.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
using namespace ATL;
//app.cpp
#include "app.h"
[module(dll, name = "app", helpstring = "APP 1.0 Type Library")];
[emitidl];
当我尝试构建解决方案时,我收到很多 MIDL2003 错误; sn-p 来自Debug\app.log
下方:
Microsoft (R) 32b/64b MIDL Compiler Version 8.01.0622
Copyright (c) Microsoft Corporation. All rights reserved.
Processing .\vc140.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\wtypes.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\wtypesbase.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\basetsd.h
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\guiddef.h
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\wincrypt.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\prsht.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\objidl.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\unknwn.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\propidlbase.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\oaidl.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\urlmon.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\oleidl.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\servprov.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\msxml.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\propidl.idl
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(56): error MIDL2003: redefinition : tagVersionedStream
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(60): error MIDL2003: redefinition : PROPSETFLAG_DEFAULT
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(61): error MIDL2003: redefinition : PROPSETFLAG_NONSIMPLE
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(62): error MIDL2003: redefinition : PROPSETFLAG_ANSI
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(64): error MIDL2003: redefinition : PROPSETFLAG_UNBUFFERED
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(66): error MIDL2003: redefinition : PROPSETFLAG_CASE_SENSITIVE
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(70): error MIDL2003: redefinition : PROPSET_BEHAVIOR_CASE_SENSITIVE
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(90): error MIDL2003: redefinition : tagCAC
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(91): error MIDL2003: redefinition : tagCAUB
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(92): error MIDL2003: redefinition : tagCAI
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(93): error MIDL2003: redefinition : tagCAUI
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(94): error MIDL2003: redefinition : tagCAL
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(95): error MIDL2003: redefinition : tagCAUL
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(96): error MIDL2003: redefinition : tagCAFLT
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(97): error MIDL2003: redefinition : tagCADBL
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(98): error MIDL2003: redefinition : tagCACY
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(99): error MIDL2003: redefinition : tagCADATE
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(100): error MIDL2003: redefinition : tagCABSTR
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(101): error MIDL2003: redefinition : tagCABSTRBLOB
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(102): error MIDL2003: redefinition : tagCABOOL
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(103): error MIDL2003: redefinition : tagCASCODE
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(104): error MIDL2003: redefinition : tagCAPROPVARIANT
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(105): error MIDL2003: redefinition : tagCAH
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(106): error MIDL2003: redefinition : tagCAUH
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(107): error MIDL2003: redefinition : tagCALPSTR
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(108): error MIDL2003: redefinition : tagCALPWSTR
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(109): error MIDL2003: redefinition : tagCAFILETIME
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(110): error MIDL2003: redefinition : tagCACLIPDATA
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(111): error MIDL2003: redefinition : tagCACLSID
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(276): error MIDL2003: redefinition : tag_inner_PROPVARIANT
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(309): error MIDL2003: redefinition : PID_DICTIONARY
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(310): error MIDL2003: redefinition : PID_CODEPAGE
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(311): error MIDL2003: redefinition : PID_FIRST_USABLE
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(312): error MIDL2003: redefinition : PID_FIRST_NAME_DEFAULT
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(313): error MIDL2003: redefinition : PID_LOCALE
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(314): error MIDL2003: redefinition : PID_MODIFY_TIME
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(315): error MIDL2003: redefinition : PID_SECURITY
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(316): error MIDL2003: redefinition : PID_BEHAVIOR
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(317): error MIDL2003: redefinition : PID_ILLEGAL
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(319): error MIDL2003: redefinition : PID_MIN_READONLY
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(320): error MIDL2003: redefinition : PID_MAX_READONLY
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(322): error MIDL2003: redefinition : PRSPEC_INVALID
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(323): error MIDL2003: redefinition : PRSPEC_LPWSTR
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(324): error MIDL2003: redefinition : PRSPEC_PROPID
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(339): error MIDL2003: redefinition : tagPROPSPEC
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(348): error MIDL2003: redefinition : tagSTATPROPSTG
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(368): error MIDL2003: redefinition : tagSTATPROPSETSTG
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(377): error MIDL2003: redefinition : IPropertyStorage
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(509): error MIDL2003: redefinition : IPropertySetStorage
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(546): error MIDL2003: redefinition : IEnumSTATPROPSTG
c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(586): error MIDL2003: redefinition : IEnumSTATPROPSETSTG
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\ocidl.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\comcat.idl
Processing C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\atlmfc\include\atliface.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\oleacc.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\shtypes.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Mshtml.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\dimm.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\dispex.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\dxgitype.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\dxgicommon.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\dxgiformat.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\MsHtmHst.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\docobj.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\ExDisp.idl
Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\ObjSafe.idl
.\vc140.idl(38): warning MIDL2214: semantic check incomplete due to previous errors
LINK : fatal error LNK1240: failed to compile IDL content
【问题讨论】:
【参考方案1】:首先,总体而言,使用 ATL 属性并不是一个好主意。您指的是属于 Visual Studio 2008 的 MSDN 部分,ATL 属性很快就被弃用了。
对我使用最新的 VS2017 的 MyIncludes.h 的编辑(其余部分按照演练步骤进行):
#pragma once
#include <sdkddkver.h> // <<--- This is the actual edit compared to MSDN article
#define _USRDLL
#define _ATL_ATTRIBUTES
#define _ATL_APARTMENT_THREADED
#define _ATL_NO_AUTOMATIC_NAMESPACE
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
using namespace ATL;
【讨论】:
我应该提到,我的代码在使用cl /LD app.cpp
时确实有效,但在 VS 2017 中构建解决方案时会引发重新定义错误。我应该在原始帖子中更加明确。关于 atl 属性的另一点,我真的不想在新代码中引入它们,但不确定我应该改用什么。你能指出我在 MSDN 上的一些东西,让我走上正确的道路吗?感谢您的见解:)
没关系,我得到了答案。我将只使用 Visual Studio ATL 项目。我认为我对 VS 2017 有疑问,因为我在其外部编写了 app.h
和 app.cpp
,然后将其导入到 VS 2017 解决方案中。我冒险走这条路是因为我试图探索是否可以在不使用 Visual Studio 的情况下进行 COM 开发(例如,只使用 VSCode)。这仍然是一个有趣的话题,但也许是另一个时间。我会将问题标记为已回答。以上是关于获取 MIDL 2003 重新定义错误的主要内容,如果未能解决你的问题,请参考以下文章
错误 MSB6006:“midl.exe”退出,代码为 2026
将我的数据从 access 2003 db 获取到 c# 的问题(dbReader.GetString 错误)