TinyRacoon
TinyRacoon

Reputation: 4903

C++ why use TLB files over the actual DLL?

I have some legacy C++ code.

I have DLL Bob. I also have program Jane.

Program Jane imports Bob through his TLB file.

#import 'Bob.tlb'

Why does Jane use Bob like that?

Why doesn't Jane use Bob like this?

#import 'Bob.dll'

I have the source code for both sides. Thanks for any help or pointers!

Upvotes: 5

Views: 5450

Answers (2)

Tongxuan Liu
Tongxuan Liu

Reputation: 280

TLB is type definition, which also can includes in DLL. If you directly use #import *.tlb or #import *.dll, the MIDL Compiler would generate .tlh and .thi which used in following compiling steps.

It's not a good choice to directly #import. If you #import the same .tlb in different cpp in same project, would introduce duplication .tlh & .tli files generated.

Upvotes: 1

Zdeslav Vojkovic
Zdeslav Vojkovic

Reputation: 14591

#importing a dll is equivalent to importing a tlb only when the dll contains the type library as the resource of ITypeLib type, as dictated by LoadTypeLib API call.

This is not always the case:

  • the dll doesn't have to contain the tlb as the resource
  • you might want to use a managed dll via COM interop: the dll doesn't contain the tlb and you have to generate it using tlbexp tool
  • there are probably other scenarios

Upvotes: 5

Related Questions