简体   繁体   中英

Use COM interface without statically linking to library

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

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

Thanks

There's no need to fight against linking windowscodecs.lib. Linking against it doesn't result in implicit linking as you would get for a non-COM library.

You still need to call CoCreateInstance() just as you would for any COM object. Think of this as being runtime binding equivalent to GetProcAddress .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM