September 22nd, 2022

How can I get WRL to link my object into its activation factory?

Recall that under the classical model for linking, symbols in libraries are not included unless they or some other symbol in the same object file is referenced by an explicitly-included object file, or indirectly via a chain of object files.

Component libraries like ATL and WRL use a linker trick to create self-registering objects. ATL has a set of object map macros for doing this, and WRL has its own macros for activatable objects and COM-creatable objects.

But if your object is in a static library, you need to do something to pull in those object files.

For ATL, Larry Osterman used the trick of calling two dummy functions in the object file from dead code.

WRL codifies the mechanism with a set of macros that create explicit references to the magic objects:

#define WrlCreatorMapIncludePragma(className)
#define WrlCreatorMapIncludePragmaex(className, serverName)
#define CoCreatableClassWrlCreatorMapInclude(className)
#define CoCreatableClassWrlCreatorMapIncludeEx(className, serverName)

Invoke those macros somewhere in the main project (next to your DllMain is a fairly obvious place), and they will pull in the object registration information.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.