COM接口继承时,如果要对接口指针进行传递,必须使用QueryInterface()来进行。
基接口:
[
object,
uuid(F20D4233-DD50-4B19-9C9A-DDCDDDA12BC6),
dual,
nonextensible,
helpstring("IPDFToken Interface"),
pointer_default(unique)
]
interface IPDFToken : IDispatch{
};
继承接口:
[
object,
uuid(E6DC748C-7310-4254-B350-27396462248B),
dual,
nonextensible,
helpstring("IPDFComment Interface"),
pointer_default(unique)
]
interface IPDFComment : IPDFToken{
};
在进行接口指针传递时,
HRESULT CPDFTokenizer::processComment(IPDFToken** ppVal)
{
CComPtr<IPDFComment> spComment;
spComment.CoCreateInstance(CLSID_PDFComment);
spComment->put_comment(str.AllocSysString());
// COM参数指针的传递
spComment->QueryInterface(IID_IPDFToken, (void**)ppVal);
}
通过QueryInterface(),则可以把COM对象传递出去。