How do I invoke the MIDL compiler to generate a .TLB file (type library) from an .IDL file?

别说谁变了你拦得住时间么 提交于 2019-12-01 07:14:12

The .idl file requires a library{} block before it will generate a type library. Inside this block you'll need to declare the types that need to be present inside the library. A normal library only has coclass definitions in the library section, midl automatically injects any interfaces that the coclasses use.

Getting just the interface requires moving it inside the library block:

[
  uuid(34DC0E7C-37C1-41C1-B3FD-1755A0396308),
  version(1.0),
]
library MyLibrary
{
    importlib("stdole2.tlb");

    [object, uuid(400075B9-4BD6-45A5-B8B7-9DA0CF7B9B13)]
    interface IFoo : IUnknown {
        HRESULT DoFoo([in] long arg, [out, retval] long *result);
    };
};

Use your own uuid, version number and name for the library. The importlib voodoo ensures that the definitions for IUnknown and GUID don't get embedded in the type library as well.

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