如何在超类中设置CComPtr上的接口
How do I set the interface on CComPtr in a Superclass?
我想尝试修改我的代码使用超类来处理创建CComPtr,但我不确定如何将类传递给CComPtr来创建,即
中的部分void CSuperClass::CreateSmartPointer(CString class, Interface interface)
{
CLSID clsid;
hr = CLSIDFromProgID(class, &clsid);
CComPtr<interface> spInterface;
hr = spInterface.CoCreateInstance(clsid, 0, CLSCTX_ALL);
}
void CSubClass::Init()
{
CreateSmartPointer("MYServer.MyClass", xxx);
}
void CSubClass2::Init()
{
CreateSmartPointer("MYServer2.MyClass2", xxx);
}
根据您想要实现的目标,模板可以完成任务:
template<class Interface> class CSuperClass {
// ...
void CreateSmartPointer(CString class) {
// ...
CComPtr<Interface> spInterface;
// ....
我认为您可以使用IIDFromString
函数来获取接口Id,然后在该接口上执行QueryInterface
。在IUnknown
上创建COM对象,然后在新解析的IID
上创建QueryInterface
。
相关文章:
- 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个方法
- 类具有相同的接口,但参数的类型不同
- 如果一个COM接口的指针分配给一个CComPtr对象,我需要释放原来的一个
- 如何在超类中设置CComPtr上的接口