magicxor / delphi-detours-library

Automatically exported from code.google.com/p/delphi-detours-library
1 stars 0 forks source link

Add a small object-oriented wrapper around DDetours #5

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
DelphiDetours is a great library!  I've been using it very happily.

One thing I thought of is that you could use it in an object-oriented way: to 
install a hook/detour object, and remove the hook by freeing the object.  
(Currently it's used only procedurally.)  So, for example:

TMyProc = function(A : Integer): Boolean; // Use this to type-safely declare 
the prototype of the method you're detouring
...
FDetour : TDetour<TMyProc>; // Using generics, now it's a detour only for this 
type of method
...
FDetour := TDetour<TMyProc>.Create(@Original, @Replacement); // Installs the 
detour
FDetour.Free; // Uninstalls the detour

Meanwhile, while it's installed, you can call the trampolined function like so:
FDetour.Trampoline(5); // Calls the trampoline / original

It's just a neat OO style of using the detour, and I think suits Delphi quite 
well.

In fact I wrote a small wrapper unit that does exactly the above, and so if you 
like it you are very welcome to add it to DDetours! I've attached it here.

Original issue reported on code.google.com by vintaged...@gmail.com on 21 May 2014 at 11:02

Attachments:

GoogleCodeExporter commented 9 years ago
Great idea , thanks  David.

Do you agree that i merge DDetoursOO.pas unit into a single unit with the 
DDetours.pas unit ?

Original comment by ismspi...@gmail.com on 22 May 2014 at 8:06

GoogleCodeExporter commented 9 years ago
Sure, feel free.  Would you mind crediting me as the author of the class though?

Original comment by vintaged...@gmail.com on 22 May 2014 at 9:06

GoogleCodeExporter commented 9 years ago
Perfect , could you send me your email .. to send you a copy before i make the 
change .
I will delete the email after you post it .

Original comment by ismspi...@gmail.com on 22 May 2014 at 9:14

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by ismspi...@gmail.com on 27 May 2014 at 3:06

GoogleCodeExporter commented 9 years ago

Original comment by Rodrigo.Ruz.V@gmail.com on 25 Jul 2014 at 3:48