2

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

VividD
  • 10,456
  • 6
  • 64
  • 111
Steven
  • 63
  • 1
  • 4

2 Answers2

3

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

wqw
  • 11,771
  • 1
  • 33
  • 41
  • 1
    This isn't available in the midl compiler. – Steven Mar 18 '10 at 22:33
  • This is a directive of the C/C++ compiler, not MIDL compiler. Put it right after your #include's – wqw Mar 19 '10 at 09:58
  • 1
    I need to bring in the information in my IDL file so that I can declare a new interface. #import only brings the information into my .h and .cpp files. – Steven Mar 22 '10 at 16:59
  • Which interface proxy/stub is not working when you use importlib? – wqw Mar 22 '10 at 21:49
  • The IDL file won't compile. The ITypeFromTLB type is undeclared. It exists in the .tlb file, but I can't figure out how to get it into the .idl file as specified in my original post. – Steven Mar 25 '10 at 17:44
  • Then why is `importlib` not working? Try `importlib("C:\\Path\\To\\Your.tlb");` in `library` scope before using `ITypeFromTLB` in methods signature. – wqw Mar 25 '10 at 20:17
  • 1
    importlib can only be used *inside* a library declaration. In order for proxy/stub stuff to work, the ISomeInterface declaration must be *before* the library declaration. importlib *cannot* be used due to limitations in its capabilities. – Steven Mar 29 '10 at 16:20
  • I see. Did you try changing the "offending" params from custom interfaces to `IUnknown`? Do you need these params to be strongly typed? – wqw Mar 29 '10 at 19:12
  • Yes - I need these interfaces to be strongly typed. – Steven Mar 30 '10 at 18:15
  • As a last resort use `OleView` to extract just the needed interfaces in an .idl from the typelib, then import this .idl file. – wqw Mar 30 '10 at 21:29
  • Yes, I've used this method. However, it's a manual process (prone to human error), and the idl is not always C++ friendly for some reason, requiring substantial human editing. Is it possible that Microsoft has overlooked a functionality so basic as this? This seems like a basic task to me, and should be easy! – Steven Mar 30 '10 at 21:48
1

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.

ZXX
  • 4,684
  • 27
  • 35