描述:
有一个Com不可创建类,实现了一个接口,这个接口由IDispatch派生,现在我得到了此接口的Dispatch指针以及这个接口中的函数名,IID和接口名字也可知道,但这些都是在程序运行时动态获得的,我怎么调用这个接口中的方法呢?(需要定义这个接口类型的变量吗?需要在运行期动态地引入类型库吗?)
解决方案1:
First get the information abou the COM component, such as interface functions, component's CLSID, and the interface's CLSID or its ProgID and so on.
With these information you can invoke it as you wish at any time in your app.
Second, after you get the interface's CLSID or ProgID, you can invoke API function ProgIDFromCLSID or CLSIDFromProgID to exchange any kind of the interface. Then invoke
API function CoCreateInstance() to initialize the COM. the rest of the jobs leave to you to finish.
不需要,你知道函数名和参数的话可以用两步法来调用:调用IDispatch::GetIDsOfNames,然后IDispatch::Invoke即可