Question

Assume we have a macro 'HELLO' defined in a .cpp file and we have built a .tlb file out of it. When I import this .tlb file in an another c++ project, do I have access to that macro?

By default if a macro is defined in .c file, the scope is within that file. If macro is defined in .h file, then everyone who includes it has access to the macro. Just wondering if the behaviour is same even via .tlb file .../

Was it helpful?

Solution

Type libraries are only storing type information (Interface & class declarations, typedef's, other meta-data), not code. The implementation of the code is defined inside the respective library (DLL) or server (EXE). This mean's type libraries are only telling clients where to find code. They do not provide code. This is why macros cannot be exported to tlb's.

OTHER TIPS

Like Aschratt said, macros are not stored in type libraries. However, if your macros are integer constants, you can use enums in the IDL file:

enum Colors
{
    White = 1,
    Yellow = 2,
    BLue = 3
}

This works with all languages. For example, if you use the type library in C#, you see the enum as a C# enum.

And if the type library is only meant to be used by a particular C++ client, you can use the cpp_quote IDL attribute to emit code in the generated header, and then use the #include directive to include that header instead of using #import to generate a new header based on the type library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top