当前位置:网站首页>About queryinterface functions
About queryinterface functions
2022-06-25 17:35:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
One ,QueryInterface function Prototype :
HRESULT __stdcall QueryInterface(const IID&iid,void **ppv);
iid: Mark the interface required by the customer . yes ” An interface identifier “ structure (IID). ppv:QueryInterface Used to store the address of the requested interface .
Return value : Can return S_OK or E_NOINTERFACE Should use the SUCEEDED perhaps FAILED Macro validation successful .
Usage method :
If you know a direction IUnknown Pointer to interface pI, Just pass it an interface identifier
for example :
void
Foo(IUnknown
*
pI)
QueryInterface Function related QueryInterface function
{
QueryInterface function IX * pIX = NULL;
QueryInterface function
QueryInterface function HRESULT hr = pI->QueryInterface(IID_IX,(void **)pIX);
QueryInterface function
QueryInterface function if(SUCCEEDED(hr))
QueryInterface Function related QueryInterface function {
QueryInterface function pIX->FX();
QueryInterface function }
QueryInterface function }
QueryInterface function
QueryInterface function
//
QueryInterface The implementation of the .
QueryInterface function
QueryInterface function HRESULT _stdcall CA::QueryInterface(
const
IID
&
iid,
void
**
ppv)
QueryInterface Function related QueryInterface function
{
QueryInterface function if(iid == IID_IUnknown)
QueryInterface Function related QueryInterface function {
QueryInterface function *ppv = static_cast<IX *>(this);
QueryInterface function }
QueryInterface function else if(iid == IID_IX)
QueryInterface Function related QueryInterface function {
QueryInterface function *ppv = static_cast<IX *>(this);
QueryInterface function }
QueryInterface function else if(iid == IID_IY)
QueryInterface Function related QueryInterface function {
QueryInterface function *ppv = static_cast<IY *>(this);
QueryInterface function }
QueryInterface function else if(iid == IID_IUnknown)
QueryInterface Function related QueryInterface function {
QueryInterface function *ppv = NULL;
QueryInterface function return E_NOINTERFACE;
QueryInterface function }
QueryInterface function
QueryInterface function static_cast <IUnknown *> (* ppv)->AddRef();
QueryInterface function retru S_OK;
QueryInterface function
QueryInterface function }
Multiple inheritance and type conversion .
Usually converting a pointer of one type to another does not change its value . To support multiple inheritance , In some cases ,C++ You must change the value of the class pointer .
Suppose a class is defined as follows :
class CA: public IX,public IY{…};
because CA At the same time inherited IX,IY So you can use IX or IY The pointer can be used everywhere CA The pointer to .
QueryInterface function
void
foo(IX
*
pIX);
QueryInterface function
void
bar(IY
*
pIY);
QueryInterface function
int
main()
QueryInterface Function related QueryInterface function
{
QueryInterface function CA* pA = new CA;
QueryInterface function foo(pA);
QueryInterface function bar(pA);
QueryInterface function delete pA;
QueryInterface function return 0;
QueryInterface function }
QueryInterface function foo Need a legal IX Pointer to the virtual function table of ; bar Need a legal IY Pointer to the virtual function table of ; Of course IX and IY The contents of the virtual function table of are different . So... One IX vtbl Pass to bar when , This function does not work properly . So the compiler passes the same pointer to foo and bar It's impossible , It has to be right CA Modify the pointer of so that it points to an appropriate vtbl The pointer . The image below shows CA Object's memory structure .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151157.html Link to the original text :https://javaforall.cn
边栏推荐
- On Web 3.0
- 杰理之获取复位源和唤醒的 IO 口的方法【篇】
- 有关QueryInterface函数
- Precautions for using timer_cap.c of Jerry [chapter]
- 杰理之系统时钟设置出现复位或无效问题【篇】
- 华为云GaussDB(for Redis)揭秘第19期:GaussDB(for Redis)全面对比Codis
- WARNING: Unsupported upgrade request.
- 用户调度问题
- Distinguishing seven kinds of facial expressions by deep separable convolution neural network
- [matlab] data interpolation
猜你喜欢
![[compilation principle] overview](/img/af/246750beb72842e83a19e42270c09e.png)
[compilation principle] overview

学习太极创客 — MQTT(二)MQTT 基本原理

【Matlab】数值微积分与方程求解

BILSTM和CRF的那些事

Learning Tai Chi maker mqtt (II) basic principles of mqtt

Super Full Metal PBR Multi - channel Mapping Materials website collation

SnakeYAML配置文件解析器
![How Jerry used to output a clock source to the outside world [chapter]](/img/ea/161be6416726bcd80bb2823a5f6389.png)
How Jerry used to output a clock source to the outside world [chapter]

杰理之系统时钟设置出现复位或无效问题【篇】

CVPR小目标检测:上下文和注意力机制提升小目标检测(附论文下载)
随机推荐
Mathematical modeling - nonlinear programming
Sword finger offer II 025 Adding two numbers in a linked list
On Web 3.0
足下教育日精进自动提交
IDEA全局搜索汉字[通俗易懂]
数据挖掘之时间序列分析[通俗易懂]
有关均衡----简易版瓶颈模型
Is Guotai Junan Securities reliable? Is it legal? Is it safe to open a stock account?
golang sort slice int
[compilation principle] overview
ES6知识点
Mobx learning path - powerful "state management tool"
Snakeyaml profile parser
【Matlab】曲线拟合
【UVM实战 ===> Episode_2 】~ VIP、VIP的开发、VIP的发布
[UVM practice== > episode_1] ~ MCDF design update, AMBA standard interface, UVM verification environment update
Jerry's system clock setting is reset or invalid [chapter]
有关QueryInterface函数
[UVM practice== > episode_2] ~ VIP, VIP development, VIP release
学习太极创客 — MQTT(三)连接MQTT服务端