How do I create interface methods using .tlb types

2019-07-19 11:56发布

Background:

  1. The .TLB file contains interfaces written in language 'X'. I don't have .h, .idl, .tlh, or any other header files - just the .TLB file. Language 'X' does not export compatible .h, .idl, etc.
  2. I use the VS wizard to add an ATL simple object to my ATL project.

I want to add a method to the interface of my simple ATL object that uses one of the .TLB defined types for a parameter.

// Something like the following in the .idl file:
interface ISomeInterface : IUnknown {
   HRESULT SomeMethod([in] ITypeFromTLB* aVal); // ITypeFromTLB declared in .TLB file.
};

How can I do this? I'm hoping for a wizard, or a line in the .idl interface declaration that would bring in the .tlb information. midl's include (no .tlb), import (no tlb), and importlib (library only) don't seem to provide a solution (I need proxy/stub to be working, so I cannot put this inside the library declaration with the importlib command).

2条回答
再贱就再见
2楼-- · 2019-07-19 12:21

Use #import in cpp/h to bring TLB interfaces to your namespace.

查看更多
Bombasti
3楼-- · 2019-07-19 12:38

On Visual Studio command line do oleview. Then File -> View Type Lib, give it full path to your foo.tlb. Now in ITypeLib Viewer do File -> Save As .. and you can export all 3 (.h, .idl, .c) from there.

查看更多
登录 后发表回答