当前位置:网站首页>有关QueryInterface函数
有关QueryInterface函数
2022-06-25 17:12:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
一,QueryInterface函数 原型:
HRESULT __stdcall QueryInterface(const IID&iid,void **ppv);
iid:标志客户所需的接口。是”一个接口标志符“结构(IID)。 ppv:QueryInterface用来存放所请求接口的地址。
返回值:可以返回S_OK 或 E_NOINTERFACE应该用SUCEEDED或者FAILED宏验证是否成功。
使用方法:
假如知道一个指向IUnknown接口的指针pI,传给它一个接口标志符即可
例如:
void
Foo(IUnknown
*
pI)
QueryInterface函数有关QueryInterface函数
{
QueryInterface函数 IX * pIX = NULL;
QueryInterface函数
QueryInterface函数 HRESULT hr = pI->QueryInterface(IID_IX,(void **)pIX);
QueryInterface函数
QueryInterface函数 if(SUCCEEDED(hr))
QueryInterface函数有关QueryInterface函数 {
QueryInterface函数 pIX->FX();
QueryInterface函数 }
QueryInterface函数}
QueryInterface函数
QueryInterface函数
//
QueryInterface的实现。
QueryInterface函数
QueryInterface函数HRESULT _stdcall CA::QueryInterface(
const
IID
&
iid,
void
**
ppv)
QueryInterface函数有关QueryInterface函数
{
QueryInterface函数 if(iid == IID_IUnknown)
QueryInterface函数有关QueryInterface函数 {
QueryInterface函数 *ppv = static_cast<IX *>(this);
QueryInterface函数 }
QueryInterface函数 else if(iid == IID_IX)
QueryInterface函数有关QueryInterface函数 {
QueryInterface函数 *ppv = static_cast<IX *>(this);
QueryInterface函数 }
QueryInterface函数 else if(iid == IID_IY)
QueryInterface函数有关QueryInterface函数 {
QueryInterface函数 *ppv = static_cast<IY *>(this);
QueryInterface函数 }
QueryInterface函数 else if(iid == IID_IUnknown)
QueryInterface函数有关QueryInterface函数 {
QueryInterface函数 *ppv = NULL;
QueryInterface函数 return E_NOINTERFACE;
QueryInterface函数 }
QueryInterface函数
QueryInterface函数 static_cast <IUnknown *> (* ppv)->AddRef();
QueryInterface函数 retru S_OK;
QueryInterface函数
QueryInterface函数}
多重继承及类型转换。
通常将一种类型的指针转换为另一种类型并不会改变它的值。为了支持多重继承,某些情况下,C++必须改变类指针的值。
假如一个类定义如下:
class CA: public IX,public IY{…};
由于CA同时继承了IX,IY因此可以使用IX或IY指针的地方均可以使用指向CA的指针。
QueryInterface函数
void
foo(IX
*
pIX);
QueryInterface函数
void
bar(IY
*
pIY);
QueryInterface函数
int
main()
QueryInterface函数有关QueryInterface函数
{
QueryInterface函数 CA* pA = new CA;
QueryInterface函数 foo(pA);
QueryInterface函数 bar(pA);
QueryInterface函数 delete pA;
QueryInterface函数 return 0;
QueryInterface函数}
QueryInterface函数foo需要一个指向合法的IX的虚拟函数表的指针; bar需要一个指向合法的IY的虚拟函数表的指针; 当然IX和IY的虚拟函数表的内容是不一样的。因此将一个IX vtbl传给bar时,此函数是不能正常工作的。 因此编译器将同一指针传给foo和bar是不可能的,它必须对CA的指针进行修改以便他指向一个合适的vtbl指针。 下图显示了CA对象的内存结构。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151157.html原文链接:https://javaforall.cn
边栏推荐
- Redis Series - Overview day1 - 1
- STM32硬件错误HardFault_Handler的处理方法
- [black apple] Lenovo Savior y70002019pg0
- Uncover ges super large scale graph computing engine hyg: Graph Segmentation
- 学习太极创客 — MQTT(三)连接MQTT服务端
- [untitled]
- Will the 2022 cloud world be better
- 足下教育日精进自动提交
- Win10开启热点共享后断网怎么解决?
- WPF development essays Collection - ECG curve drawing
猜你喜欢

Why are there few embedded system designers in the soft test?

社交电商如何运营推广?

Involution? Foam? Change? Ten questions directly hit the core puzzle of "meta universe" – the essence of "ask ta- Wang Lei about the time of the universe"
![[black apple] Lenovo Savior y70002019pg0](/img/9c/7a94aa911dd0c6b94ba192bc2687e6.png)
[black apple] Lenovo Savior y70002019pg0

超全金屬PBR多通道貼圖素材網站整理

Super Full Metal PBR Multi - channel Mapping Materials website collation

Mathematical modeling -- integer programming

超全金属PBR多通道贴图素材网站整理

旧手机变废为宝,充当服务器使用

软考中的嵌入式系统设计师为什么考的人少?
随机推荐
上线移动ERP系统有哪些步骤?环环紧扣很重要
Which is better for intermediate and advanced soft exam?
Why are there few embedded system designers in the soft test?
What are the steps for launching the mobile ERP system? It's important to keep it tight
芝士糖豆打造AR潮玩新体验
TCP chat + transfer file server server socket v2.8 - fix 4 known problems
Is Guotai Junan Securities reliable? Is it legal? Is it safe to open a stock account?
中断操作:AbortController学习笔记
Xshell connecting VMware virtual machines
剑指 Offer II 025. 链表中的两数相加
Internship: the annotation under swagger involves the provision of interfaces
大学生暑假换机热,ROG 明星产品幻 16 翻转版 / 幻 13 / 幻 X 预约
Old mobile phones turn waste into treasure and serve as servers
Kotlin入门(20)几种常见的对话框
How do components communicate
社交电商如何运营推广?
golang list to string
剑指 Offer II 014. 字符串中的变位词 滑动窗口
[efficiency] another note artifact is open source!
Sword finger offer II 014 A sliding window of anagrams in strings