How to retrieve the Interface ID of a COM class so that it can be passed to CoCreateInstance?

后端 未结 3 2093
执笔经年
执笔经年 2021-01-02 05:24

I want to programaticly retrieve the Interface ID for any class so that I can pass it to CoCreateInstance. Any help is very much appreciated!!

See \"How Do I Get

相关标签:
3条回答
  • 2021-01-02 05:37

    platform SDK is distributed with source code of OleView utility, t contains pretty good example to build tree of all possible CLSIDs and them names

    0 讨论(0)
  • 2021-01-02 05:47

    You already know it. It's going to be the compile-time output type that you want the function to store in the pInterface variable that you've given it.

    In other words, what interface type are you going to treat that object you've created as? Which interface's methods are you going to call on it?

    The type you get from CLSIDFromProgID might be any version of the interface, including one that didn't even exist at the time you compiled your code. You can usually assume that whatever version is available at run time also supports some lesser version that you know about at compile time. You ask the OS to instantiate an instance of the recent version, but then you also ask it to return a reference to the lesser version's interface — the one you know how to handle.

    The function calls QueryInterface on the object for you, using the type you requested, something like this:

    obj->QueryInterface(riid, pInterface);
    

    If you have nothing more specific to request, just use IUnknown.

    0 讨论(0)
  • 2021-01-02 05:48

    You need to know upfront what interface you ask for. This you get from the product specifications, from SDK header files, or you can import the TLB of the COM object into your project.

    the easisest way is to use #import

    0 讨论(0)
提交回复
热议问题