'Redefinition error in propidlbase.idl when compiling ATL project in Visual Studio 2019
I am trying to migrate a previous an older project from Visual Studio 2010 to a current version of Visual Studio (2019). I Microsoft's change notes on upgrading and there seem to be some changes in using ATL attributes in VS 2019 compared to how it was done before.
I am able to compile the project in I am getting a bunch of redefinition errors when trying to compile this project in Visual Studio 2019.
4>64 bit Processing .\vc140.idl
4>vc140.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\wtypes.idl
4>wtypes.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\wtypesbase.idl
4>wtypesbase.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\basetsd.h
4>basetsd.h
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\guiddef.h
4>guiddef.h
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\wincrypt.idl
4>wincrypt.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\prsht.idl
4>prsht.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\objidl.idl
4>objidl.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\unknwn.idl
4>unknwn.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\propidlbase.idl
4>propidlbase.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\oaidl.idl
4>oaidl.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\urlmon.idl
4>urlmon.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\oleidl.idl
4>oleidl.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\servprov.idl
4>servprov.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\msxml.idl
4>msxml.idl
4>64 bit Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\propidl.idl
4>propidl.idl
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(56): error MIDL2003: redefinition : tagVersionedStream
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(60): error MIDL2003: redefinition : PROPSETFLAG_DEFAULT
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(61): error MIDL2003: redefinition : PROPSETFLAG_NONSIMPLE
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(62): error MIDL2003: redefinition : PROPSETFLAG_ANSI
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(64): error MIDL2003: redefinition : PROPSETFLAG_UNBUFFERED
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(66): error MIDL2003: redefinition : PROPSETFLAG_CASE_SENSITIVE
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(70): error MIDL2003: redefinition : PROPSET_BEHAVIOR_CASE_SENSITIVE
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(90): error MIDL2003: redefinition : tagCAC
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(91): error MIDL2003: redefinition : tagCAUB
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(92): error MIDL2003: redefinition : tagCAI
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(93): error MIDL2003: redefinition : tagCAUI
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(94): error MIDL2003: redefinition : tagCAL
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(95): error MIDL2003: redefinition : tagCAUL
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(96): error MIDL2003: redefinition : tagCAFLT
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(97): error MIDL2003: redefinition : tagCADBL
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(98): error MIDL2003: redefinition : tagCACY
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(99): error MIDL2003: redefinition : tagCADATE
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(100): error MIDL2003: redefinition : tagCABSTR
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(101): error MIDL2003: redefinition : tagCABSTRBLOB
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(102): error MIDL2003: redefinition : tagCABOOL
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(103): error MIDL2003: redefinition : tagCASCODE
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(104): error MIDL2003: redefinition : tagCAPROPVARIANT
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(105): error MIDL2003: redefinition : tagCAH
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(106): error MIDL2003: redefinition : tagCAUH
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(107): error MIDL2003: redefinition : tagCALPSTR
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(108): error MIDL2003: redefinition : tagCALPWSTR
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(109): error MIDL2003: redefinition : tagCAFILETIME
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(110): error MIDL2003: redefinition : tagCACLIPDATA
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(111): error MIDL2003: redefinition : tagCACLSID
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(276): error MIDL2003: redefinition : tag_inner_PROPVARIANT
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(309): error MIDL2003: redefinition : PID_DICTIONARY
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(310): error MIDL2003: redefinition : PID_CODEPAGE
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(311): error MIDL2003: redefinition : PID_FIRST_USABLE
4>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\propidlbase.idl(312): error MIDL2003: redefinition : PID_FIRST_NAME_DEFAULT
This is what is in my stdafx.h file:
#pragma once
#include <SDKDDKVer.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
#include <comdef.h>
using namespace ATL;
Diving into the code it looks like this #if macro is what is triggering the second definition to be included. From propidlbase.idl
cpp_quote("#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM)")
Does this have do with the project or compiler settings, or maybe I need another #define? Is there anything in particular, ie hidden solution setting, that is in 2019 that need to be set in order to use ATL attributes in an application project that would cause an error like this?
EDIT: Per Simon's comment this is the imports of the generated idl file that I tried to compile using midl:
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\wincrypt.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\prsht.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\objidl.idl";
import "c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\unknwn.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\propidlbase.idl";
import "c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\oaidl.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\urlmon.idl";
import "c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\oleidl.idl";
import "c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\servprov.idl";
import "c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\msxml.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\propidl.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\ocidl.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\comcat.idl";
import "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\atlmfc\include\atliface.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\oleacc.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\shtypes.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\MsHTML.idl";
import "c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\dimm.idl";
import "c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\dispex.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\dxgitype.idl";
import "c:\program files (x86)\windows kits\10\include\10.0.17763.0\shared\dxgicommon.idl";
import "c:\program files (x86)\windows kits\10\include\10.0.17763.0\shared\dxgiformat.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\MsHtmHst.idl";
import "c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\docobj.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\ExDisp.idl";
import "C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\ObjSafe.idl";
Solution 1:[1]
You should start with oa/oc/ole idls, and not use direct SDK paths, otherwise, there are good chances that the midl compiler will get confused.
Just make sure midl.exe is in the path (like when using the Visual Studio 2019 developer command prompt), and use as simplified .idl like this:
import "ocidl.idl";
import "oleidl.idl";
import "oaidl.idl";
import "wincrypt.idl";
import "prsht.idl";
import "objidl.idl";
import "unknwn.idl";
import "propidlbase.idl";
import "urlmon.idl";
import "servprov.idl";
import "msxml.idl";
import "comcat.idl";
import "atliface.idl";
import "oleacc.idl";
import "shtypes.idl";
import "MsHTML.idl";
import "dimm.idl";
import "dispex.idl";
import "dxgitype.idl";
import "dxgicommon.idl";
import "dxgiformat.idl";
import "MsHtmHst.idl";
import "docobj.idl";
import "ExDisp.idl";
import "ObjSafe.idl";
Solution 2:[2]
@LT21j
At some point in the history of Visual C++, the library file um\propidl.idl was changed to #include "propidlbase.idl"
. You'll see in your listing snippet in your question, vc140.idl imports propidlbase.idl, and then a handful of lines later imports propidl.idl. That's what triggers the MIDL2003 redefinition errors.
What you want is to have it import probidl.idl instead of propidlbase.idl - not both.
I wish I could tell you how to change the import list in the auto-generated vc140.idl, but I don't know how to do that. Instead, this worked for me:
- Take the generated vc140.idl and rename it to something more meaningful.
- Edit your renamed .idl file:
- Move the import for propidl.idl up higher so that it replaces the import for propidbase.idl.
- In all the import statements, strip out the paths to the .idl files, leaving just the filename (e.g.
import "oaidl.idl
). You don't want this to break when you upgrade Visual C++ again. - For unrelated reasons, I found I had to also remove the import for ShObjIdl.idl; it used an invalid attribute (disable_consistency_check). You might not need this, or you might find the proposed workaround (Specify “/target NT60” in Project Properties->MIDL-> Command Line -> Additional Options) does the trick. You'll have to see which works for you.
- Put your new, renamed .idl file in the same folder as the rest of the source code, and add it to your project. (Add | Existing item...)
- Tell the Linker to not use a generated .idl file. Solution Explorer | project | Properties | Linker | Embedded IDL | Ignore Embedded IDL = Yes (/IGNOREIDL)
This worked for me, I hope it works for you.
Solution 3:[3]
According to Microsoft Documents, the error MIDL2003 is: Your toolchain is set up to automatically reference any types that are in system namespaces. In your IDL files, remove any import
directives for Windows namespaces; you only need to import
any types that you've defined in your project.
You could edit the stdafx.h and refer to this link for more information.
#pragma once
#include <sdkddkver.h> //<---- This is the edit.
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
#include <comdef.h>
using namespace ATL;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Simon Mourier |
Solution 2 | Dan K |
Solution 3 | Barrnet Chou |