How do I create interface methods using .tlb types in VS C++?

北城余情 提交于 2019-12-12 21:17:35

问题


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).


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/2473595/how-do-i-create-interface-methods-using-tlb-types-in-vs-c

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