Use COM interface without static binding to the library

This may be a beginner's question, but I just don't know! To use a function in a DLL that may not be available on the system, I can use LoadLibrary and then GetProcAddress . But how can I do the same for the COM interface? I can include the header file for declarations, IID, etc., but I don’t want to reference the accompanying library using #pragma comment(lib, "blabla.lib") .

(I'm trying to use the WICImagingFactory interface, and to compile it requires linking to windowscodecs.lib)

thanks

+4
source share
1 answer

There is no need to deal with windowscodecs.lib binding. Linking to it does not lead to implicit linking, as you will get for a library other than COM.

You still need to call CoCreateInstance() just like you would for any COM object. Think of it as a run-time binding equivalent to GetProcAddress .

+5
source

All Articles