Question

    [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 ?

Was it helpful?

Solution

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);

OTHER TIPS

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top