How to hook class instance method with detours?

78 Views Asked by At

I've been trying to hook the GetSelectedItems function inside Shobjdl_core.h

 virtual HRESULT STDMETHODCALLTYPE GetSelectedItems( 
            /* [out] */ __RPC__deref_out_opt IShellItemArray **ppsai) = 0;

Since it is a virtual function, I cannot compile the code.

HRESULT(WINAPI* TrueSleep)(IShellItemArray** ppsai) = GetSelectedItems;

// Detour function that replaces the Sleep API.
//
HRESULT WINAPI TimedSleep(IShellItemArray** ppsai)
{
    return 0;
}

The error is:

Error C2065 'GetSelectedItems': undeclared identifier DllCreateFile

Is there an example for hooking of class instance methods?

Only link is this one.

1

There are 1 best solutions below

3
Baris LaPaz On

Solution is:

HRESULT(WINAPI IFileOpenDialog::* TrueSleep)(IShellItemArray** ppsai) = &IFileOpenDialog::GetSelectedItems;



HRESULT WINAPI TimedSleep(IShellItemArray** ppsai)
{
    return 0; 
}