4

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

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Ha! You are right, I renamed C:\Windows\System32\WindowsCodecs.dll to C:\Windows\System32\WindowsCodecs.bak (after taking ownership grrr) and my application runs fine except that CoCreateInstance fails, which is no problem, I've got some fallback mechanism to good old GDI functions :) Thanks heaps!
You could make CoCreateInstance succeed by updating the registry entries for your CLSID to point to WindowsCodecs.bak :)
Ok nice to know, but I was just testing how my application would respond when WindowsCodecs.dll is not found, removing it entirely felt so crude ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.