当前位置:网站首页>有关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
边栏推荐
- 「津津乐道播客」#386 原汤话原食:谁还不是个“白字先生”?
- Super Full Metal PBR Multi - channel Mapping Materials website collation
- Internship: the annotation under swagger involves the provision of interfaces
- [efficiency] another note artifact is open source!
- SDN system method | 10 The future of SDN
- WPF开发随笔收录-心电图曲线绘制
- Sword finger offer 39 Numbers that occur more than half the time in the array
- 用连续自然数之和来表达整数
- Next. JS hot update markdown file change
- try with resource
猜你喜欢

pytorch官方文档学习记录

剑指 Offer 50. 第一个只出现一次的字符

项目经理在项目中起到的作用

足下教育日精进自动提交

杰理之唤醒口使用注意事项【篇】

ddia数据密集型应用系统设计 整理

Design and arrangement of DDIA data intensive application system

How does social e-commerce operate and promote?

杰理之如何给外界输出一个时钟源使用【篇】

Distinguishing seven kinds of facial expressions by deep separable convolution neural network
随机推荐
CVPR small target detection: context and attention mechanisms improve small target detection (attached with paper Download)
PLSQL 存储函数SQL编程
浅谈 Web 3.0
Assembly language (5) register (memory access)
剑指 Offer 39. 数组中出现次数超过一半的数字
Sword finger offer II 035 Minimum time difference
Tasklet API usage
Design and arrangement of DDIA data intensive application system
Solution to the problem of incorrect clock in FreeRTOS kernel
Treasure and niche Chinese painting 3D texture material website sharing
宝藏又小众的国画3d材质贴图素材网站分享
Sword finger offer II 025 Adding two numbers in a linked list
[UVM practice== > episode_2] ~ VIP, VIP development, VIP release
The role of the project manager in the project
杰理之adc_get_voltage 函数获取电压值不准【篇】
Redis series - overview day1-1
记一次基于PHP学生管理系统的开发
ES6 knowledge points
golang list to string
Which is better for intermediate and advanced soft exam?