Fix compile errors in C++ wrapper

Fixes #14.
This commit is contained in:
Zeex 2016-08-13 01:58:55 +06:00
parent d2a5756f49
commit cba3854843
7 changed files with 32 additions and 29 deletions

View File

@ -119,7 +119,10 @@ class SubHook
{
public:
SubHook() : hook_(0) {}
SubHook(void *src, void *dst) : hook_(subhook_new(src, dst)) {}
SubHook(void *src,
void *dst,
subhook_options_t options = (subhook_options_t)0)
: hook_(subhook_new(src, dst, options)) {}
~SubHook() {
subhook_remove(hook_);
@ -134,9 +137,11 @@ public:
return subhook_install(hook_) >= 0;
}
bool Install(void *src, void *dst) {
bool Install(void *src,
void *dst,
subhook_options_t options = (subhook_options_t)0) {
if (hook_ == 0) {
hook_ = subhook_new(src, dst);
hook_ = subhook_new(src, dst, options);
}
return Install();
}

View File

@ -1,7 +1,7 @@
add_library(test_lib SHARED test_lib.c test_lib.def)
add_library(test_lib SHARED test_lib.cpp test_lib.def)
target_link_libraries(test_lib subhook)
add_executable(test_prog test_prog.c)
add_executable(test_prog test_prog.cpp)
target_link_libraries(test_prog test_lib)
add_test(NAME test COMMAND $<TARGET_FILE:test_prog>)

View File

@ -1,4 +1,4 @@
foo_hook\(\) called
foo_hooked\(\) called
foo\(\) called
foo_hook\(\) called
foo_hooked\(\) called
foo\(\) called

View File

@ -4,6 +4,6 @@ void foo() {
printf("foo() called\n");
}
void foo_hook() {
printf("foo_hook() called\n");
void foo_hooked() {
printf("foo_hooked() called\n");
}

View File

@ -1,3 +1,3 @@
EXPORTS
foo
foo_hook
foo_hooked

View File

@ -1,19 +0,0 @@
#include <subhook.h>
extern void foo();
extern void foo_hook();
subhook_t hfoo;
int main() {
hfoo = subhook_new((void *)foo, (void *)foo_hook, 0);
subhook_install(hfoo);
foo();
subhook_remove(hfoo);
foo();
subhook_install(hfoo);
foo();
subhook_remove(hfoo);
foo();
subhook_free(hfoo);
}

17
test/test_prog.cpp Normal file
View File

@ -0,0 +1,17 @@
#include <subhook.h>
extern void foo();
extern void foo_hooked();
SubHook foo_hook;
int main() {
foo_hook.Install((void *)foo, (void *)foo_hooked);
foo();
foo_hook.Remove();
foo();
foo_hook.Install();
foo();
foo_hook.Remove();
foo();
}