c++ - 如何使用 COM 智能指针作为调用的输入输出参数库函数

标签 c++ com smart-pointers

使用 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&的定义旁边有注释:

The assert on operator& usually indicates a bug. If this is really what is needed, however, take the address of the p member explicitly.

所以调用你的函数使用

FunctionPrototype(&test.p);

关于c++ - 如何使用 COM 智能指针作为调用的输入输出参数库函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9062417/

相关文章:

c++ - boost::scoped_ptr 文档不一致?

c++ - 一起使用 smart_pointer 和 set_new_handler

c++ - 使用二维字符数组读取一个句子直到按下 ENTER 键

c++ - D3DCompileFromFile 未解析的外部

c++ - std::regex 线程安全吗?

c++ - 在 C++ 中使用 map 时输出顺序错误

php - 为什么 COM 类在 PHP 5.4.5 中不再存在?

c++ - CoMarshalInterThreadInterfaceInStream 为 Visual Basic 6 类返回 0x800A0062

c++ - 是否有解决方法来解决 C++ 中智能指针对指针算术的限制?

java - 是否可以在Java上编写active-x组件?