How to import a tlb and a namespace in c++ at runt

2019-05-23 16:34发布

问题:

Generally we import a tlb file at the starting of the program like

#include < stdio.h >
#import " sql.tlb "

But i need to import a tlb file when certain condition meets in the middle of the program

how can i do this. to load dll there is LoadLibrary() but to load tlb can i use LoadLibrary().

Since tlb is generated by using .dll?

回答1:

You can load a type library at runtime using LoadTypeLib.

ITypeLib *ptlib;
LoadTypeLib("sql.tlb", &ptlib);

What you do then with ptlib is kind of up in the air as you don't really say what you are trying to do with it.

ptlib is an object supporting the ITypeLib interface. It has methods which you can call to enumerate and iterate the types in the type library. Normally you use it in combination with the other interfaces like ITypeInfo and so on.

I found a fuller tutorial style document here. Also, this link here has some more detail, also it shows the header file and link library you need to use.

Header                    oaidl.h, oaidl.idl
Library                   oleaut32.lib, uuid.lib
Windows Embedded CE       Windows CE 2.0 and later
Windows Mobile            Windows Mobile Version 5.0 and later