如何使用COM智能指针作为内外参数来调用例如库函数

How to use COM smart pointer as in-out arguments for calling e.g. library functions

本文关键字:参数 调用 库函数 COM 何使用 智能 指针      更新时间:2023-10-16

使用CComPtr或_com_ptr智能指针作为输入输出参数的最佳方式是什么?

void FunctionPrototype(Test** test) {
    // you can use here test or create a new Test here and assign to test
}
CComPtr<Test> test;
test.CoCreateInstance(..., ..., ...);
test->SetValue(10);
FunctionPrototype(&test); // assertion since test.p is not NULL

CComPtr<T>::operator&:的定义旁边有一条注释

对运算符&通常表示存在错误。如果这真的然而,需要的是显式地获取p成员的地址。

所以使用调用您的函数

FunctionPrototype(&test.p);