views:

358

answers:

4

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

Thanks.

+2  A: 

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

wqw
This isn't available in the midl compiler.
Steven
This is a directive of the C/C++ compiler, not MIDL compiler. Put it right after your #include's
wqw
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
Which interface proxy/stub is not working when you use importlib?
wqw
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
Then why is `importlib` not working? Try `importlib("C:\\Path\\To\\Your.tlb");` in `library` scope before using `ITypeFromTLB` in methods signature.
wqw
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
I see. Did you try changing the "offending" params from custom interfaces to `IUnknown`? Do you need these params to be strongly typed?
wqw
Yes - I need these interfaces to be strongly typed.
Steven
As a last resort use `OleView` to extract just the needed interfaces in an .idl from the typelib, then import this .idl file.
wqw
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
A: 

I am experiencing the same problem. Did you find any solution?

Pooh
+1  A: 

Pooh - I have found no adequate solution. Hopefully Microsoft will consider supporting this workflow in the future

Steven
I have the same issue unfortunately. It's irritating that this basic functionality is not available.
emddudley
A: 

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