DWORD conversion

1

Hello, I have the following code snippet

#include <windows.h>
#include <d3d8.h>
#include <d3dx8.h>

#pragma comment(lib, "d3d8.lib")
#pragma comment(lib, "d3dx8.lib")

typedef HRESULT(WINAPI* CreateDevice_Prototype)        (LPDIRECT3D8, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE8*);
typedef HRESULT(WINAPI* Reset_Prototype)               (LPDIRECT3DDEVICE8, D3DPRESENT_PARAMETERS*);
typedef HRESULT(WINAPI* EndScene_Prototype)            (LPDIRECT3DDEVICE8);
typedef HRESULT(WINAPI* DrawIndexedPrimitive_Prototype)(LPDIRECT3DDEVICE8, D3DPRIMITIVETYPE, UINT, UINT, UINT, UINT);
CreateDevice_Prototype         CreateDevice_Pointer = NULL;
Reset_Prototype                Reset_Pointer = NULL;
EndScene_Prototype             EndScene_Pointer = NULL;
DrawIndexedPrimitive_Prototype DrawIndexedPrimitive_Pointer = NULL;

HRESULT WINAPI CreateDevice_Detour(LPDIRECT3D8, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE8*);
HRESULT WINAPI Reset_Detour(LPDIRECT3DDEVICE8, D3DPRESENT_PARAMETERS*);
HRESULT WINAPI EndScene_Detour(LPDIRECT3DDEVICE8);
HRESULT WINAPI DrawIndexedPrimitive_Detour(LPDIRECT3DDEVICE8, D3DPRIMITIVETYPE, UINT, UINT, UINT, UINT);
PDWORD Direct3D_VMTable = NULL;

HRESULT WINAPI InstallD3DHook(VOID);
void ResetHook(LPDIRECT3DDEVICE8);
void EndSceneHook(LPDIRECT3DDEVICE8);


HRESULT WINAPI InstallD3DHook(VOID)
    {
        LPDIRECT3D8 Direct3D_Object = Direct3DCreate8(D3D_SDK_VERSION);

    if (Direct3D_Object == NULL)
        return D3DERR_INVALIDCALL;

    Direct3D_VMTable = (PDWORD)*(PDWORD)Direct3D_Object;
    Direct3D_Object->Release();

    DWORD dwProtect;

    if (VirtualProtect(&Direct3D_VMTable[15], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
    {
        *(PDWORD)&CreateDevice_Pointer = Direct3D_VMTable[15];
        *(PDWORD)&Direct3D_VMTable[15] = (DWORD)CreateDevice_Detour;

        if (VirtualProtect(&Direct3D_VMTable[15], sizeof(DWORD), dwProtect, &dwProtect) == 0)
            return D3DERR_INVALIDCALL;
    }
    else
        return D3DERR_INVALIDCALL;

    return D3D_OK;
}

which works perfectly, however, when using the same code inside a class like the one below:

    #include <windows.h>
    #include <d3d8.h>
    #include <d3dx8.h>

    #pragma comment(lib, "d3d8.lib")
    #pragma comment(lib, "d3dx8.lib")

    class Hook
    {
    private:
            typedef HRESULT(WINAPI* CreateDevice_Prototype)        (LPDIRECT3D8, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE8*);
            typedef HRESULT(WINAPI* Reset_Prototype)               (LPDIRECT3DDEVICE8, D3DPRESENT_PARAMETERS*);
            typedef HRESULT(WINAPI* EndScene_Prototype)            (LPDIRECT3DDEVICE8);
            typedef HRESULT(WINAPI* DrawIndexedPrimitive_Prototype)(LPDIRECT3DDEVICE8, D3DPRIMITIVETYPE, UINT, UINT, UINT, UINT);

    CreateDevice_Prototype         CreateDevice_Pointer = NULL;
    Reset_Prototype                Reset_Pointer = NULL;
    EndScene_Prototype             EndScene_Pointer = NULL;
    DrawIndexedPrimitive_Prototype DrawIndexedPrimitive_Pointer = NULL;

    HRESULT WINAPI CreateDevice_Detour(LPDIRECT3D8, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE8*);
    HRESULT WINAPI Reset_Detour(LPDIRECT3DDEVICE8, D3DPRESENT_PARAMETERS*);
    HRESULT WINAPI EndScene_Detour(LPDIRECT3DDEVICE8);
    HRESULT WINAPI DrawIndexedPrimitive_Detour(LPDIRECT3DDEVICE8, D3DPRIMITIVETYPE, UINT, UINT, UINT, UINT);
    PDWORD Direct3D_VMTable = NULL;
public:
    HRESULT WINAPI InstallD3DHook(VOID);
    void ResetHook(LPDIRECT3DDEVICE8);
    void EndSceneHook(LPDIRECT3DDEVICE8);
    };

    HRESULT WINAPI Hook::InstallD3DHook(VOID)
    {
        LPDIRECT3D8 Direct3D_Object = Direct3DCreate8(D3D_SDK_VERSION);

        if (Direct3D_Object == NULL)
            return D3DERR_INVALIDCALL;

Direct3D_VMTable = (PDWORD)*(PDWORD)Direct3D_Object;
Direct3D_Object->Release();

DWORD dwProtect;

if (VirtualProtect(&Direct3D_VMTable[15], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
{
    *(PDWORD)&CreateDevice_Pointer = Direct3D_VMTable[15];
    *(PDWORD)&Direct3D_VMTable[15] = (DWORD)CreateDevice_Detour;

    if (VirtualProtect(&Direct3D_VMTable[15], sizeof(DWORD), dwProtect, &dwProtect) == 0)
        return D3DERR_INVALIDCALL;
        }
        else
            return D3DERR_INVALIDCALL;

        return D3D_OK;
    }

I get the following error on the line:

  

(PDWORD) & Direct3D_VMTable [15] = (DWORD) CreateDevice_Detour;

logo in cast (DWORD):

typdef unsigned long DWORD
conversão de tipo inválida

Can anyone explain the reason for this error ??

    
asked by anonymous 15.11.2018 / 18:22

0 answers