使用 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/