C#: DLL Injection

  • Thread starter Thread starter Ryan Ross
  • Start date Start date
R

Ryan Ross

Hello,

I'm curious if anyone could describe the settings needed for a C#
project to inject a C dll (setup a windows hook) into a running process.

Thanks,
Ryan
 
It is impossible to do this in pure C#. You can write a C dll which injects
code and use it in C# via P/Invoke using DllImport attribute to import and
use native functions from your C dll.
 
Yes. The problem I'm faced with is that the C dll does not appear to be
working. More precisely, the dll injects just fine in the alpha code,
but appears not to work in the beta code. Here's some snippets:

The DLL injection code (same in both the alpha and the beta):


public class PaintHook
{
[DllImport ("PaintHook.dll", EntryPoint="#1")]
public static extern IntPtr InstallHook();

}

This code works fine in the alpha, but does not work in the beta.
Invocation of the dll is PaintHook.InstallHook(). The dll is activated
by sending a custom message via SendMessage().

For the life of me, I cannot figure out why it's not working. The dll
copies a window into a bitmap (which exists in shared memory, which the
C# component accesses), something akin to the PrintWindow() function.

As a test, I changed the dll to close a window when activated. Alpha
code closes the window, beta does not. Very simple code (InstallHook,
SendMessage methods), should work in both. No dice.

Any theories as to why the dll works only in the one? Am I missing some
security or project settings that are the cause?

Thanks,
Ryan
 
Back
Top