How do I use a COM DLL with LoadLibrary in C++

后端 未结 6 2057
我寻月下人不归
我寻月下人不归 2020-12-16 02:45

First, COM is like black magic for me. But I need to use COM dll in one project I\'m working on.

So, I have a DLL I am developing and I need some functionalities tha

6条回答
  •  情书的邮戳
    2020-12-16 03:22

    You do not directly use LoadLibrary() with a COM library. CoCreateInstance() will call this function if it's not already, and then new an instance of the class you implemented in the library onto the heap and finally return to you a raw pointer to that object. Of course, it could fail during the process, and thus some mechanism for you to check the status like HRESULT.

    For simplicity of using it, you can think of a COM library as a common DLL with 1) some predefined entry(main) function, 2) you have to call some predefined function like CoCreateInstance() to enter it, and accept that it's like that because it has to.

提交回复
热议问题