mr.sir bossman
2005-07-17 11:17:01 UTC
I am new to using VirtualAlloc and was wondering if someone could tell me
what I am doing wrong.
I get a "First-chance exception in XXXX.exe: 0xC0000005: Access Violation."
struct _WndProcThunk
{
DWORD m_mov; //32bits
DWORD m_this; //32bits
BYTE m_jmp; //8 bits
DWORD m_relproc; //32bits 13 bytes?
};
class CWndProcThunk
{
public:
CWndProcThunk()
{
thunk = (_WndProcThunk *)VirtualAlloc(NULL,13,MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE );
}
_WndProcThunk *thunk;
void Init(WNDPROC proc, void* pThis)
{
thunk->m_mov = 0x042444C7; //C7 44 24 0C
thunk->m_this = (DWORD)pThis;
thunk->m_jmp = 0xe9;
thunk.m_relproc = (int)proc - ((int)this+sizeof(_WndProcThunk));
FlushInstructionCache(GetCurrentProcess(), thunk, 13);
}
};
WNDPROC pProc = (WNDPROC)&(pThis->m_thunk.thunk);
::SetWindowLong(hwnd, GWL_WNDPROC, (LONG)pProc);
what I am doing wrong.
I get a "First-chance exception in XXXX.exe: 0xC0000005: Access Violation."
struct _WndProcThunk
{
DWORD m_mov; //32bits
DWORD m_this; //32bits
BYTE m_jmp; //8 bits
DWORD m_relproc; //32bits 13 bytes?
};
class CWndProcThunk
{
public:
CWndProcThunk()
{
thunk = (_WndProcThunk *)VirtualAlloc(NULL,13,MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE );
}
_WndProcThunk *thunk;
void Init(WNDPROC proc, void* pThis)
{
thunk->m_mov = 0x042444C7; //C7 44 24 0C
thunk->m_this = (DWORD)pThis;
thunk->m_jmp = 0xe9;
thunk.m_relproc = (int)proc - ((int)this+sizeof(_WndProcThunk));
FlushInstructionCache(GetCurrentProcess(), thunk, 13);
}
};
WNDPROC pProc = (WNDPROC)&(pThis->m_thunk.thunk);
::SetWindowLong(hwnd, GWL_WNDPROC, (LONG)pProc);