See the question and my original answer on StackOverflow

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