Void pointer pointer (void **)

I am reading a COM sample at http://msdn.microsoft.com/en-us/library/windows/desktop/dd389098 (v = vs .85) .aspx

I really can't understand (void **) in

hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);

So, I tried some values ​​returned by various types of pointers by the class

class Point{
private:
    int x, y;
public:
    Point(int inputX, int inputY){x = inputX, y = inputY;}
    int getX(){return x;}
    int getY(){return y;}
    friend ostream& operator << (ostream &out, Point &cPoint);
    Point operator-(){
        return Point(-x, -y);
    }
};

ostream& operator << (ostream &out, Point &cPoint){
    return out<< "(" << cPoint.x << ", " << cPoint.y << ")";
}

and print

Point *p = new Point(1,2);
cout << p << endl << &p << endl << endl
<< *&p << endl<< **&p << endl<<endl 
<< (void *) &p << endl << (void **) &p ;

(void *) really has no difference with (void **). What do you want (void **) & pControl want to return?

+4
source share
1 answer
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);

What returns (void **)&pControl?

QueryInterface()is one of three methods IUnknown, which is the basic root interface of all COM interfaces.

MSDN IUnknown::QueryInterface() , :

HRESULT QueryInterface(
  [in]   REFIID riid,
  [out]  void **ppvObject
);

ppvObject [out] , , riid. * ppvObject . , * ppvObject NULL.

, pControl IMediaControl, IID_IMediaControl.


, : void**.

void* " ".

, : " QueryInterface() a void*?"

, output. , QueryInterface() - , .

, C ( COM C-isms), , (*).
( ++ &.)

, void*, " ".
( *), : " output".

:

typedef void* PointerToAnything;

HRESULT QueryInterface(..., /* [out] */ PointerToAnything* pSomeInterface);

// pSomeInterface is an output parameter.
//
// [out] --> use * (pointer), 
// so it 'PointerToAnything*' (not just 'PointerToAnything'),
// so, with proper substitution, it 'void**' (not just 'void*').
+4

Source: https://habr.com/ru/post/1536651/


All Articles