ADDR IID_SomeOtherInterface, ADDR ppv_new

 


I hope you find this as wonderfully simple as I do.

 

Note we must pass in the pointer we used, this lets the interface know which object (literally "this" object) we are using.

 

Note the register must be type cast (IUnknown PTR [edx]). This lets the compiler know what structure to use to get the correct offset in the vtable for the .QueryInterface function (in this case it means an offset of zero from [edx]). Actually, the information contained by the interface name and function name called disappear at compile time, all that is left is a numeric offset from an as of yet value unspecified pointer.

 

One more semi-obscure point. Notice I changed the interface method name from simply "QueryInterface" to "IUnknown_QueryInterface". This is a bit of name decoration I've found necessary. When you get to larger COM projects with many similar interfaces you will run into a problem, that is different interfaces with identical method names. This is quite valid, in fact it's called polymorphism, but can confuse the compiler a bit.

 

Without this name decoration scheme things will be safe until you have two different interfaces with identical method names but different parameters to that method. This is more common then you might first think, but just consider how many interfaces might have a PRINT method.

 

The coinvoke Macro

--------------------------------------------------------------------------------------------------------------------
We can simplify a COM invoke further with a macro. This coinvoke macro is part of the oaidl.inc file.

 

;---------------------------------------------------------------------