0
    [DllImport("user32.dll")]
    public static extern int FindWindow(string lpClassName, string lpWindowName);
    [DllImport("user32.dll")]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

Like this. I need both 'em. if I go for intptr, it cant be converted to int propely so postmessage etc stuff fails, other way, stuff that requires "handle" fails because its supposed to be pointer.

        Bitmap thisScreenshot = new Bitmap(Width, Height);
        Graphics gfxScreenshot = Graphics.FromImage(thisScreenshot);
        IntPtr hdcBitmap = gfxScreenshot.GetHdc();
        PrintWindow(handle, hdcBitmap, 0);
        gfxScreenshot.ReleaseHdc(hdcBitmap);

I basically want to execute this while also having my int findwindow function. any ideas how ? also Findwindow IS the handle, right ?

a23ch
  • 1
  • 1
  • @HansPassant: Ah, ok. I should go read the docs again then. I've not done much interop stuff and assumed from the context of the question that it was. Thanks for the correction (and deleting the original comment since it is now a bit embarrassing). – Chris Jul 27 '12 at 10:21

2 Answers2

2

It is never correct to use the version that returns int. FindWindow returns a window handle, it is always IntPtr. You'll need to fix your PostMessage declaration instead:

[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • thank you, this is fixed my problem. I never realized that postmessage was supposed to be used like that, fool me. Btw, if you dont mind, can you lead me to a link that explains how can I do get messages(wm_stuff) like spy++ does so I can do actions based on that? I have found something about wndproc but I ended up in nowhere. – a23ch Jul 27 '12 at 12:09
0

Give the function a different name and use entrypoint to specify the original name

[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint="FindWindow")]
public static extern IntPtr FindWindowA(string lpClassName, string lpWindowName);
Simon Halsey
  • 5,459
  • 1
  • 21
  • 32