COM querying Interfaces

1
2
3
Interface* pAnotherInterface;

IcomPtr->QueryInterface(IID_Interface, (LPVOID*) &pAnotherInterface);


Why do we need (LPVOID*) then &pAnotherInterface ??

Why can't we just pass in the addressOf operator?

is that being used as a cast to a pointer? Whats the purpose of that?


so my understanding is that it is being casted as a void pointer.

void pointers can point to any datatype.

Last edited on
Why do we need (LPVOID*) then &pAnotherInterface ?
void* is a pointer to anything. As we don't know the type of the actual object, a void* is used to point to it. Obviously, it'll need to be cast to something before use, but that shouldn't interfere with use getting the pointer to begin with.

void** is used because we're passing the void* by reference. In C, you have to explicitly do that by passing the address of the thing you want filled in. The type of the address of a void* is void**, in the same way that the type of the address of an int is int*.

Why can't we just pass in the addressOf operator?
I'm not sure what addressOf is. But it's standard practice in C to pass by reference in that way.

is that being used as a cast to a pointer? Whats the purpose of that?
QueryInterface returns all COM interfaces, so it has to use void*, the user has to make sense of what that means. The rest has already been explained.
Last edited on
Topic archived. No new replies allowed.