Page 1 of 1

HookAPI crashes without calling InitializeMadCHook

PostPosted: Wed Jul 11, 2018 1:30 pm
by _NN_
Is it possible to just fail and return FALSE instead of producing Access Violation when HookAPI is called without InitializeMadCHook ?

Re: HookAPI crashes without calling InitializeMadCHook

PostPosted: Wed Jul 11, 2018 2:10 pm
by madshi
It's difficult, especially when using the Delphi LIB, because if you don't call InitializeMadCHook(), the whole Delphi RTL is not even initialized at all.

It would not be difficult to make HookAPI() not crash, it's just one API, but I'd have to add the same check to each and every exported function, and in Delphi that's a lot more than madCHook.h contains. So a lot of work and added code, just to protect against incorrect usage? Not sure if I like that...

Re: HookAPI crashes without calling InitializeMadCHook

PostPosted: Wed Jul 11, 2018 2:24 pm
by _NN_
You can add it inline in the header if you don't want to touch Delphi source.
I understand it is incorrect usage, but I spent several minutes trying to understand why I have crash in some irrelevant address.

Re: HookAPI crashes without calling InitializeMadCHook

PostPosted: Wed Jul 11, 2018 4:02 pm
by madshi
Well, FWIW, I always recommend to use one of the demo projects as the starting point for your own projects. That way you already have the basic framework set up correctly, including compiler and linker settings etc.

Re: HookAPI crashes without calling InitializeMadCHook

PostPosted: Thu Jul 12, 2018 7:09 am
by _NN_
This discussion goes to direction who is responsible to check the caller or the callee.
My opinion that callee will do as much checks as possible, while you say it is not really necessary.

I already made a class which does this automatically, so I won't forget :)
Btw, perhaps you need some C++ API on top of your header which will take care of all this initializations.
Is it something that you would accept as patch ?

Re: HookAPI crashes without calling InitializeMadCHook

PostPosted: Wed Jul 18, 2018 8:05 am
by madshi
I'm not sure if I'd like a C++ API. I like a simple and short API. And if I distribute your C++ API, I also become responsible for maintaining it and fixing bugs in it. And if I add or change APIs, I also have to do all that in the C++ API files in addition to the current C header.

Anyway, how complicated is your C++ API? Does it fit into a single e.g. *.h file?

Re: HookAPI crashes without calling InitializeMadCHook

PostPosted: Wed Jul 18, 2018 11:11 am
by _NN_
Currently I removed all wrappers since the code is very simple.
Maybe in the future I'll do wrapping which will initialize madCodeHook automatically on first call if wasn't initialized before or smth like that.