举个栗子
ComPtr pMPSCEv = aEvent;
上面这个在com下是可以编译的,但是实际在vs下无法通过的,通过对原版程序逆向发现,上面这个函数的实现是以下代码
xor ebx, ebx
mov [rbp+57h+bstrString], rbx
test rdi, rdi
jz short loc_13F3D44B7
mov rax, [rdi] //rdi =IEvent *aEvent,eax为虚指针=this
lea r8, [rbp+57h+bstrString]
lea rdx, _GUID_a6dcf6e8_416b_4181_8c4a_45ec95177aef
mov rcx, rdi
call qword ptr [rax] //this的第一个函数,通过查表发现是QueryInterface函数
所以上面的操作转换为vs下为:
IMousePointerShapeChangedEvent *pMPSCEv;
IID riid = {0xa6dcf6e8,0x416b,0x4181,{0x8c,0x4a,0x45,0xec,0x95,0x17,0x7a,0xef}};
//通过调试发现实际上,通过QueryInterface函数获取相应的指针
aEvent->QueryInterface(riid,(void **)&pMPSCEv);
IMousePointerShapeChangedEvent的定义
EXTERN_C const IID IID_IMousePointerShapeChangedEvent;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("a6dcf6e8-416b-4181-8c4a-45ec95177aef")
IMousePointerShapeChangedEvent : public IEvent
{
public:
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Visible(
/* [retval][out] */ BOOL *aVisible) = 0;
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Alpha(
/* [retval][out] */ BOOL *aAlpha) = 0;
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Xhot(
/* [retval][out] */ ULONG *aXhot) = 0;
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Yhot(
/* [retval][out] */ ULONG *aYhot) = 0;
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Width(
/* [retval][out] */ ULONG *aWidth) = 0;
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Height(
/* [retval][out] */ ULONG *aHeight) = 0;
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Shape(
/* [retval][out] */ SAFEARRAY * *aShape) = 0;
};
#else /* C style interface */
typedef struct IMousePointerShapeChangedEventVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IMousePointerShapeChangedEvent * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
__RPC__deref_out void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
IMousePointerShapeChangedEvent * This);
ULONG ( STDMETHODCALLTYPE *Release )(
IMousePointerShapeChangedEvent * This);
HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )(
IMousePointerShapeChangedEvent * This,
/* [out] */ UINT *pctinfo);
HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )(
IMousePointerShapeChangedEvent * This,
/* [in] */ UINT iTInfo,
/* [in] */ LCID lcid,
/* [out] */ ITypeInfo **ppTInfo);
HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )(
IMousePointerShapeChangedEvent * This,
/* [in] */ REFIID riid,
/* [size_is][in] */ LPOLESTR *rgszNames,
/* [range][in] */ UINT cNames,
/* [in] */ LCID lcid,
/* [size_is][out] */ DISPID *rgDispId);
/* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )(
IMousePointerShapeChangedEvent * This,
/* [in] */ DISPID dispIdMember,
/* [in] */ REFIID riid,
/* [in] */ LCID lcid,
/* [in] */ WORD wFlags,
/* [out][in] */ DISPPARAMS *pDispParams,
/* [out] */ VARIANT *pVarResult,
/* [out] */ EXCEPINFO *pExcepInfo,
/* [out] */ UINT *puArgErr);
/* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Type )(
IMousePointerShapeChangedEvent * This,
/* [retval][out] */ VBoxEventType *aType);
/* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Source )(
IMousePointerShapeChangedEvent * This,
/* [retval][out] */ IEventSource **aSource);
/* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Waitable )(
IMousePointerShapeChangedEvent * This,
/* [retval][out] */ BOOL *aWaitable);
HRESULT ( STDMETHODCALLTYPE *SetProcessed )(
IMousePointerShapeChangedEvent * This);
HRESULT ( STDMETHODCALLTYPE *WaitProcessed )(
IMousePointerShapeChangedEvent * This,
/* [in] */ LONG aTimeout,
/* [retval][out] */ BOOL *aResult);
/* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Visible )(
IMousePointerShapeChangedEvent * This,
/* [retval][out] */ BOOL *aVisible);
/* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Alpha )(
IMousePointerShapeChangedEvent * This,
/* [retval][out] */ BOOL *aAlpha);
/* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Xhot )(
IMousePointerShapeChangedEvent * This,
/* [retval][out] */ ULONG *aXhot);
/* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Yhot )(
IMousePointerShapeChangedEvent * This,
/* [retval][out] */ ULONG *aYhot);
/* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Width )(
IMousePointerShapeChangedEvent * This,
/* [retval][out] */ ULONG *aWidth);
/* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Height )(
IMousePointerShapeChangedEvent * This,
/* [retval][out] */ ULONG *aHeight);
/* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Shape )(
IMousePointerShapeChangedEvent * This,
/* [retval][out] */ SAFEARRAY * *aShape);
END_INTERFACE
} IMousePointerShapeChangedEventVtbl;
interface IMousePointerShapeChangedEvent
{
CONST_VTBL struct IMousePointerShapeChangedEventVtbl *lpVtbl;
};