Skip to content

Instantly share code, notes, and snippets.

@slimsag
Created December 17, 2021 20:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slimsag/33a0aba712d0ce9439aa92b0e12c2320 to your computer and use it in GitHub Desktop.
Save slimsag/33a0aba712d0ce9439aa92b0e12c2320 to your computer and use it in GitHub Desktop.

WIDL compiler incompatibilities with Windows SDK

I attempted to compile the IDL files distributed in https://github.com/microsoft/win32metadata/tree/master/generation/WinSDK/RecompiledIdlHeaders using the latest (7.0.1-rc.1) version of the Wine IDL compiler, called WIDL. Unlike Microsoft's MIDL compiler which ships with Visual Studio, WIDL is open source.

More importantly, WIDL contains patches to generated header files that make e.g. COM calling conventions compatible with mingw-w64 and clang when targetting GNU ABI.

Bugs

Imports are incorrectly case sensitive

WIDL's import statement is case sensitive, Microsoft's MIDL compiler is not: it treats all imports as case-insensitive filepath matches.

import "OAIDL.IDL", import "oaidl.idl", etc. should match a file named OAIdl.Idl

Additionally, the Windows SDK and win32metadata IDL files do NOT use any form of standardized casing in imports. The same file will often be referred to three different ways (OAIdl.Idl, oaidl.idl, and OAIDL.IDL for example.)

WIDL does not allow double slashes in string literals

The Windows SDK IDL files often place quotes in string literals, for example to emit comments in the generated header files:

cpp_quote("// URL Moniker Interfaces.")

WIDL fails to parse these correctly and reports a missing terminating ) instead.

Segmentation faults

I did not debug these, but found WIDL segfaults on the following files from the Windows SDK:

propidl.idl
propidlbase.idl
relogger.idl
bitscfg.idl
bits1_5.idl
bits2_0.idl
bits2_5.idl
bits3_0.idl
bits4_0.idl
bits5_0.idl
bits10_1.idl
bits10_2.idl
bits10_3.idl

Unexpected end of file during preprocessing

Affects ~15 files.

compiling ./wmsinternaladminnetsource.idl
./wmsinternaladminnetsource.idl:188:18: error: Unexpected end of file during preprocessing

compiling ./audioenginebaseapo.idl
./audioenginebaseapo.idl:1435:18: error: Unexpected end of file during preprocessing

compiling ./audioclientactivationparams.idl
./audioclientactivationparams.idl:55:18: error: Unexpected end of file during preprocessing

compiling ./wmsbuffer.idl
./wmsbuffer.idl:143:18: error: Unexpected end of file during preprocessing

compiling ./wmsdkidl.idl
./wmsbuffer.idl:143:18: error: Unexpected end of file during preprocessing

compiling ./wmdxva.idl
./wmdxva.idl:73:18: error: Unexpected end of file during preprocessing

add_text_to_macro assertion failed

Affects ~7 files.

compiling ./wsdbase.idl
widl: tools/wrc/ppl.l:1342: add_text_to_macro: Assertion `mep->ppp->expanding == 0' failed.
Aborted

compiling ./mimeole.idl
widl: tools/wrc/ppl.l:1342: add_text_to_macro: Assertion `mep->ppp->expanding == 0' failed.
Aborted

compiling ./wincrypt.idl
widl: tools/wrc/ppl.l:1342: add_text_to_macro: Assertion `mep->ppp->expanding == 0' failed.
Aborted

Missing language features

WIDL requires forward declarations, MIDL does not

This affects ~40 files.

For example, objidlbase.idl from the Windows SDK expects to be able to

typedef [unique] IMultiQI* LPMULTIQI;

interface IMultiQI : IUnknown
    ...
...

Microsoft's MIDL allows this, while WIDL views it as illegal (IMultiQI is not defined)

Annotations are not allowed

This affects ~215 files.

The Windows SDK declares annotations in the form of e.g.:

typedef struct D3D12_SHADER_BYTECODE
{
    [annotation("_Field_size_bytes_full_(BytecodeLength)")] const void* pShaderBytecode;
    SIZE_T BytecodeLength;
} D3D12_SHADER_BYTECODE;

WIDL does not allow annotation() at all, it seems.

Multi line help strings not allowed

WIDL fails to parse the multi-line help strings found in the Windows SDK IDL files, e.g.:

interface IUri : IUnknown
{
    [helpstring("Uri_PROPERTYs represent properties that an URI may contain.  "
        "The Uri_PROPERTIYs in the range Uri_PROPERTY_STRING_START to "
        "Uri_PROPERTY_STRING_LAST are string properties and the rest are DWORD "
        "properties.")]
    typedef enum
    ...

Single-line helpstring invocations are allowed by WIDL, however.

IUnknown interface type resolution

Affects ~85 files.

It's unclear why, but the MIDL compiler is able to resolve the IUnknown interface which is defined in unknwnbase.idl of the Windows SDK without importing it. For example, dbsrst.idl has no IDL imports and yet depends on it. I can only assume MIDL treats IUnknown as a builtin.

WIDL is unable to resolve this:

64-bit integer constants

Affects ~15 files.

MIDL utilizes 64-bit integer constants, whih WIDL appears to not support:

compiling ./xamlom.idl
../shared/sdkddkver.h:284:32: error: integer constant 0xFFFF0000 is too large

compiling ./vds.idl
../shared/sdkddkver.h:284:32: error: integer constant 0xFFFF0000 is too large

inapplicable attribute helpstring for enum member

Affects ~4 files.

MIDL allows helpstring attributes on enum members, WIDL does not:

compiling ./imapi2.idl
./imapi2.idl:73: error: inapplicable attribute helpstring for enum member

Other issues

Missing stdole32.tlb, stdole2.tlb

Affects ~57 files.

The win32metadata project merely copies the IDL files from the Windows SDK and makes those open source. However, those IDL files also depend on type libraries (shipped with windows?)

WIDL cannot locate them:

compiling ./sapi.idl
error: cannot find stdole32.tlb
compiling ./msclus.idl
error: cannot find stdole2.tlb

Uncategorized

There were a handful of other uncategorized issues we did not investigate.

compiling ./wdstptmgmt.idl
./wdstptmgmt.idl:86: error: 'PWDSTRANSPORT_FEATURE_FLAGS': [v1_enum] attribute applied to non-enum type

compiling ./smtpevent.idl
./smtpevent.idl:719: error: 'PMTI_NEXT_HOP_TYPE': [v1_enum] attribute applied to non-enum type

compiling ./netlistmgr.idl
./netlistmgr.idl:565: error: syntax error, unexpected ';', expecting '{'

./documenttarget.idl:141: error: syntax error, unexpected ';', expecting '{'

compiling ./msctf.idl
./msctf.idl:529: error: redefinition of struct TF_PERSISTENT_PROPERTY_HEADER_ACP

compiling ./icontentprefetchertasktrigger.idl
./icontentprefetchertasktrigger.idl:18: error: inapplicable attribute annotation for function IsRegisteredForContentPrefetch

compiling ./windows.data.pdf.interop.idl

compiling ./wincodec.idl
./wincodec.idl:1381: error: parameter 'ppbData' of function 'GetDataPointer' cannot derive from void *

compiling ./certexit.idl
./certmod.idl:32: error: instantiation of data is illegal

compiling ./directmanipulation.idl
./directmanipulation.idl:276:1: warning: Newline in string constant encountered (started line 275)
./directmanipulation.idl:288:1: warning: Newline in string constant encountered (started line 287)
./directmanipulation.idl:300:1: warning: Newline in string constant encountered (started line 299)
./directmanipulation.idl:314:1: warning: Newline in string constant encountered (started line 313)
./directmanipulation.idl:326:1: warning: Newline in string constant encountered (started line 325)
./directmanipulation.idl:340:1: warning: Newline in string constant encountered (started line 339)

./directmanipulation.idl:272: error: syntax error, unexpected aSTRING, expecting ')'

./msdatsrc.idl:36: error: syntax error, unexpected $undefined, expecting ')'

compiling ./sapiaut.idl
./sapiaut.idl:179: error: expression is not constant

compiling ./wbemtran.idl
./wbemtran.idl:47: error: inapplicable attribute size_is for typedef

compiling ./sapiddk.idl
./sapiddk.idl:486: error: syntax error, unexpected ';'

compiling ./certpol.idl
./certmod.idl:32: error: instantiation of data is illegal

compiling ./objidl.idl
error: write_conf_or_var_desc: couldn't find variable cRequest in Finish_Pull

compiling ./tspubplugincom.idl
./tspubplugincom.idl:46: error: syntax error, unexpected tLONG, expecting ')'

compiling ./objidlbase.idl
error: write_conf_or_var_desc: couldn't find variable cRequest in Finish_Pull

compiling ./ctfutb.idl
./ctfutb.idl:218: error: interface ITfLangBarMgr already defined at ./ctfutb.idl:181

compiling ./wbemads.idl
./wbemdisp.idl:2121: error: inapplicable attribute nonextensible for dispinterface ISWbemSinkEvents

compiling ./icontact.idl
./icontact.idl:979: warning: duplicate attribute ref, unique or ptr
./icontact.idl:1062: warning: duplicate attribute ref, unique or ptr

compiling ./vmr9.idl
./vmr9.idl:92: warning: duplicate attribute local
./vmr9.idl:164: warning: duplicate attribute local
./vmr9.idl:196: warning: duplicate attribute local
./vmr9.idl:221: warning: duplicate attribute local
./vmr9.idl:278: warning: duplicate attribute local
./vmr9.idl:474: warning: duplicate attribute local
./vmr9.idl:627: warning: duplicate attribute local
./vmr9.idl:664: warning: duplicate attribute local
./vmr9.idl:1065: warning: duplicate attribute local

compiling ./naptypes.idl
./naptypes.idl:102: error: 'string': [range] attribute applied to non-integer type

compiling ./wuapi.idl
./wuapi.idl:313: error: syntax error, unexpected aSTRING, expecting ')'

compiling ./windows.graphics.imaging.interop.idl

compiling ./documenttarget.idl
./documenttarget.idl:35:1: warning: Newline in string constant encountered (started line 34)

compiling ./certmod.idl
./certmod.idl:32: error: instantiation of data is illegal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment