c++windowsvisual-studiovisual-studio-2019atl

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

  • 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";