How shall I injects code into methods of an assembly by DotNetHook ?

G

Guest

Hi,all

U can download dotNetHookLibrary in http://dotnethook.sourceforge.net .

for instance, I have the fellowing code :
//------------------------------------------------------------------------
using System;
namespace hook
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
testHook();
}
public static void testHook()
{
Console.WriteLine("Help me");

}
}
}
//-------------------------------------------------------------------------
If anyone know how to injects code into testHook() by DotNetHook ,plz tell
me!

BTW,if you can do it, plz email to me, My email is (e-mail address removed) .
:)


thank you
ZhongHua
 
E

Eyal Safran

What do you mean by: "inject code"??? do you mean creating methods in
runtime?
like Reflection.Emit does?

Eyal.
 
J

Jonathan Allen

I'm missing the top of the thread, but I assume he's talking about Aspect
Orientated Programming. AOP involves using some weird compiler tricks in
literally insert extra code into a method. A bunch of voodoo BS if you ask
me. I've never seen a non-trivial example where it would be useful, and
because the code doesn't match the source, debugging is impossible.
 
E

Eyal Safran

Jonathan said:
I'm missing the top of the thread, but I assume he's talking about Aspect
Orientated Programming. AOP involves using some weird compiler tricks in
literally insert extra code into a method. A bunch of voodoo BS if you ask
me. I've never seen a non-trivial example where it would be useful, and
because the code doesn't match the source, debugging is impossible.

Sounds like Reflection.Emit ... creating types and methods in runtime.

Eyal.
 
J

Jon Skeet [C# MVP]

Jonathan Allen said:
I'm missing the top of the thread, but I assume he's talking about Aspect
Orientated Programming. AOP involves using some weird compiler tricks in
literally insert extra code into a method. A bunch of voodoo BS if you ask
me. I've never seen a non-trivial example where it would be useful, and
because the code doesn't match the source, debugging is impossible.

For plenty of non-trivial examples where AOP is useful, look at the
documentation for the Spring Framework (http://www.springframework.org)
where it's mostly used for declarative security and transaction
support.

At work we're using it in conjunction with annotations (the Java
version of attributes) for declaring code boundaries that should be
logged when an exception occurs - it saves wrapping each method in the
same try/catch/log/rethrow block which would otherwise be necessary.

I believe this is one area where .NET is behind Java, unfortunately. I
would love to be able to decorate methods in UI class with an attribute
called something like [RunInUIThread] which would automatically check
whether or not Control.Invoke was required and use it if so...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top