使用实现多个接口的coclass
Using coclass that implements multiple interfaces
我正在编写一个C++/CLI应用程序,该应用程序使用了一个提供多个类的COM dll。它们中的大多数实现了许多接口。我想知道如何访问各个接口的方法。例如,当我查看类型库时,其中一个类被定义为:
coclass FWFile {
[default] interface IFWFile;
interface _IFWFileInternal;
[default, source] interface _FWFileEvents;
interface CStatistics;
interface IFWFile2;
interface IFWFile3;
interface IFWFile4;
};
当我创建这种类型的对象时,它似乎实现了IFWFile接口。但是,我想使用IFWFile2中的方法。我可以简单地创建一个IFWFile2类型的对象并强制转换它吗?
IFWFile2 file2 = (IFWFile2)file1;
使用CoCreateInstance()
时,可以指定从新创建的对象中检索哪个接口。如果需要多个接口,请在调用CoCreateInstance()
时检索一个,并使用QueryInterface()
检索其他接口。不要忘记为每次成功的接口检索调用Release()
。
只是不要C样式强制转换COM指针-接口不能保证按照类型库中指定的顺序,并且不能保证实际类实际实现了接口。始终使用QueryInterface()
从COM对象中检索接口指针。
相关文章:
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- Visual C++GC接口如何启用它以及要包含哪个库
- Windows.h与GLFW.h的接口
- 当字段可以为null时,如何使用C++接口在Avro中写入数据
- 提供与TMP和SFINAE的通用接口
- 为重写std::exception的库生成swig接口时出错
- 内联如何影响模块接口中的成员函数
- COM 接口 c# 封送数组数组
- 如何在 SCIP C++ 接口中获取 MILP 约束矩阵中的系数值
- 重载 -> shared_ptr 个实例中的箭头运算符<interface>,接口中没有纯虚拟析构函数
- 如何绑定 C++ gRPC 客户端的网络接口
- 模板化接口 - 创建一个泛型模板类以返回任何容器
- 如何从实现接口的模板化类实例访问结构
- 带有进度表的 curl 多接口程序
- 设计帮助 - 为不同类型的消息处理通用接口的设计模式
- 我可以在具有一个标头和一个接口的 cpp 文件中有多个嵌入吗?
- 类接口,可以创建N个方法
- 类具有相同的接口,但参数的类型不同
- 使用 ATL 编译 dll,并将方法参数作为接口,但将它们作为 coclass 获取
- 使用实现多个接口的coclass