当前位置:网站首页>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
边栏推荐
猜你喜欢

College Students' hot summer exchange, Rog star product phantom 16 flipped version / phantom 13 / phantom x appointment

Uncover ges super large scale graph computing engine hyg: Graph Segmentation

STM32 hardware error hardfault_ Handler processing method

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

LSF如何看job预留slot是否合理?

Mathematical modeling -- integer programming

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

Old mobile phones turn waste into treasure and serve as servers

Singleton mode application

Why are there few embedded system designers in the soft test?
随机推荐
Website arrangement of super all metal PBR multi-channel mapping materials
BILSTM和CRF的那些事
PSYNC command of redis
Sword finger offer II 012 The sum of left and right subarrays is equal
【编译原理】词法分析
jupyter的使用
智能对话01-redis的安装
[micro service sentinel] overview of flow control rules | detailed explanation of flow control mode for source | < direct link >
数学建模——整数规划
学习太极创客 — MQTT(三)连接MQTT服务端
什么是公链开发?公链开发项目有哪些?
Treasure and niche Chinese painting 3D texture material website sharing
Which is better for intermediate and advanced soft exam?
[UVM practice== > episode_2] ~ VIP, VIP development, VIP release
Create a new ar fashion experience with cheese and sugar beans
n-queens problem
【黑苹果】联想拯救者Y70002019PG0
golang sort slice int
Singleton mode application
足下教育日精进自动提交