当前位置:网站首页>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
边栏推荐
- 超全金属PBR多通道贴图素材网站整理
- Is Guotai Junan Securities reliable? Is it legal? Is it safe to open a stock account?
- 智能对话01-redis的安装
- 宝藏又小众的国画3d材质贴图素材网站分享
- Old mobile phones turn waste into treasure and serve as servers
- [matlab] numerical calculus and equation solving
- Sword finger offer II 025 Adding two numbers in a linked list
- College Students' hot summer exchange, Rog star product phantom 16 flipped version / phantom 13 / phantom x appointment
- 有关QueryInterface函数
- 学习太极创客 — MQTT(一)MQTT 是什么
猜你喜欢
随机推荐
Next.js 热更新 Markdown 文件变更
[UVM practice== > episode_1] ~ MCDF design update, AMBA standard interface, UVM verification environment update
try with resource
[matlab] data interpolation
启牛涨乐财付通下载是可以开户吗?开户安全吗
Learning Tai Chi makers - mqtt (I) what is mqtt
【Matlab】数值微积分与方程求解
bert之我的小总结
杰理之定时器使用注意事项【篇】
ES6知识点
超全金屬PBR多通道貼圖素材網站整理
匯編語言(5)寄存器(內存訪問)
DDD concept is complex and difficult to understand. How to design code implementation model in practice?
ES6 knowledge points
揭秘GES超大规模图计算引擎HyG:图切分
【Matlab】数据插值
Create a new ar fashion experience with cheese and sugar beans
A development of student management system based on PHP
Sword finger offer II 010 Subarray prefix sum difference with sum K
Introduction to the container of() function