Читайте также:
|
|
mov edx, [eax]
Push the function parameters onto the stack
Push OFFSET ppv2
Push OFFSET IID_ISomeOtherInterface
Push dword ppv
And then call that method
call dword ptr [eax + 0]
This may be accomplished using the built-in MASM 'invoke' macro as such:
Get pointer to the object mov eax, ppv
And use it to find the interface structure
mov edx, [eax]
; and then call that method
invoke (IUnknown PTR [edx]).IUnknown_QueryInterface, ppv,
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.
;---------------------------------------------------------------------
Coinvoke MACRO
;
Invokes an arbitrary COM interface
;
Revised 12/29/00 to check for edx as a param and force compilation error
; (thanks to Andy Car for a how-to suggestion)
Revised 7/18/00 to pass pointer in edx (not eax) to avoid confusion with
; parmas passed with ADDR (Jeremy Collake's excellent suggestion)
Revised 5/4/00 for member function name decoration
See http://ourworld.compuserve.com/homepages/ernies_world/coinvoke.htm
;
PInterface pointer to a specific interface instance
Interface the Interface's struct typedef
Function which function or method of the interface to perform
Дата добавления: 2014-12-18; просмотров: 105 | Поможем написать вашу работу | Нарушение авторских прав |