What do you do when MIDL can't create a tlb?

痞子三分冷 提交于 2019-12-04 08:15:40

There are two kinds of COM. The original kind, dating from the early nineties, targeted to make interop work in C or C++ and originated by the Office group at Microsoft. And the later kind, a subset of COM originally named OLE Automation. Developed by the Visual Basic team in the DevDiv group when they looked for an alternative for VBX, a 16-bit extension model for early versions of Visual Basic. Later renamed to ActiveX as a marketing term. Gaining lots of notoriety for being insecure, renamed back to plain COM.

Automation has been incredibly successful beyond the VB usage, any language runtime in Windows supports it. Significantly helped by it implementing a strict subset of COM that was easy to implement. And for supporting type libraries, a language-independent way to make a compiler aware of declarations.

That did not supplant the "old" COM, still very heavily used in Windows. Lots of apis are "old" style. The standard bat-signal for the non-Automation kind is seeing "cppquote" in the IDL file. Or interfaces that derive from IUnknown instead of IDispatch. Or methods using raw arrays instead of SAFEARRAY. Or structure types that comes from a Windows SDK header, the kind that only a C or C++ compiler can read.

Everything you see back in sbtsv.idl.

MIDL doesn't have any actual knowledge of the Automation restrictions, it just compiles the IDL and pig-headedly calls the ICreateTypeInfo interface methods in oleauto32. Which can easily object when the type library format doesn't support it. The error message sucks, it doesn't tell you exactly what declaration was at fault. Not unusual for MIDL, or Windows SDK tools in general, diagnostics are not its strength. DevDiv creates the friendly tools.

It doesn't otherwise takes a lot of guessing what declaration is at fault in sbtsv.idl. About all of them. You really do have to do this the hard way, writing the [ComImport] declarations yourself. Painful and error prone, do consider a C++/CLI wrapper instead.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!