Hooking the functions in Opengl32.dll causes crash

c++ / delphi package - dll injection and api hooking
Post Reply
easygot
Posts: 6
Joined: Mon Oct 25, 2004 7:15 pm

Hooking the functions in Opengl32.dll causes crash

Post by easygot »

Here is my DLL code: I create a process to inject the dll to system wide process.And use another application to test the function,but everytime I call the glBegin(),first my MessageBox(for testing use) poping up,then the error Messagebox comes up.Help me:

#include "stdafx.h"
#include "madCHook.h"
#include "GL.H"


void (*glBeginNext)(GLenum cap);
void glBeginCallback(GLenum cap)
{
MessageBox(NULL,"Do you want to use this func?","haha",MB_OK);

glBeginNext(cap);
}

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch(ul_reason_for_call)
{
case(DLL_PROCESS_ATTACH):InitializeMadCHook();
HookAPI("opengl32.dll","glBegin",glBeginCallback,(PVOID*)&glBeginNext);
break;
case(DLL_PROCESS_DETACH):
FinalizeMadCHook();
break;
}


return TRUE;
}
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Which calling convention does glBegin use? Does it use WINAPI or CDECL?
easygot
Posts: 6
Joined: Mon Oct 25, 2004 7:15 pm

Post by easygot »

In GL.h,the definition of glBegin is:
WINGDIAPI void APIENTRY glBegin (GLenum mode);
SO it should be API ,right?
easygot
Posts: 6
Joined: Mon Oct 25, 2004 7:15 pm

Post by easygot »

The ERROR Messagebox is:
Image
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Well, I don't know exactly how WINGDIAPI and APIENTRY are defined. I guess this should work it work:

void WINAPI (*glBeginNext)(GLenum cap);
void WINAPI glBeginCallback(GLenum cap)
easygot
Posts: 6
Joined: Mon Oct 25, 2004 7:15 pm

Post by easygot »

Thx,it works now.
Post Reply