Skip to content

Commit

Permalink
added example
Browse files Browse the repository at this point in the history
  • Loading branch information
dzonerzy committed Nov 11, 2020
1 parent 1a2d7b1 commit 9075f7c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions MaxHook/examples/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <hook.h> // <MaxHook.h>

void MHOOK_CALLBACK onEnter(MHInvocationContext* ctx) {
printf("Called Beep(%d, %d);\n", mhook_get_parameter(ctx, 0), mhook_get_parameter(ctx, 1));
printf("Return address => 0x%p\n", mhook_get_return_address(ctx));
}

void MHOOK_CALLBACK onLeave(MHInvocationContext* ctx) {
mhook_replace_return_value(ctx, 1337);
printf("Leave\n");
}

int main() {
mhook_init();
unsigned long long hookId = mhook_add(Beep, onEnter, onLeave);
if (hookId > 0) {
int ret = Beep(100, 1000);
if (mhook_remove(hookId))
printf("Hook removed\n");
printf("Beep return: %d\n", ret);
// This won't be triggered by the hook
Beep(100, 1000);
}
mhook_deinit();
}
4 changes: 2 additions & 2 deletions MaxHook/src/includes/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#endif

#define MHOOK_EXPORTED(t) __declspec(dllexport) t
#define MHOOK __stdcall
#define MHOOK_CALLBACK __stdcall

typedef struct _MHListener MHListener;
typedef struct _Hook Hook;
typedef void* MHInvocationContext;
typedef void (MHOOK* HookCallback)(MHInvocationContext* ic);
typedef void (MHOOK_CALLBACK* HookCallback)(MHInvocationContext* ic);

struct _MHListener
{
Expand Down

0 comments on commit 9075f7c

Please sign in to comment.