问题
I have a very simple program that I am trying to compile before I build it out any further. I am trying to learn COM so following along here, I create app.h
and app.cpp
file in VS 2017 and using the ATL Template. When I try to build the solution I get a lot of MIDL 200 redefinition errors.
UPDATE (Based on @Roman R.'s response) Note that if I used cl /LD app.cpp
on a Dev Command Line, I am able to generate app.dll
correctly. The MIDL 2003 redefinition errors show up only when trying to build the solution through Visual Studio. I am working with VS 2017 Community edition, so not sure if other versions of Visual Studio have the same problem.
My Include path is simply inherited from the parent defaults i.e. the standard $(VC_IncludePath)
and $(WindowsSDK_IncludePath)
. My Windows SDK version is 10.0.17763.0 and MSVC version is 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];
When I try to build the solution, I get a lot of MIDL2003 errors; snippet from Debug\app.log
below:
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:
First of all, using ATL attributes is not a good idea overall. You are referring to MSDN section which belongs to Visual Studio 2008, and ATL attributes were deprecated soon.
An edit of MyIncludes.h that worked for me with latest VS2017 (the rest is per the walkthrough steps):
#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;
来源:https://stackoverflow.com/questions/53974096/getting-midl-2003-redefinition-errors