我怎么能有2个dll函数实例但仍然使用它们?

时间:2012-07-27 10:07:07

标签: c# postmessage findwindow

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

喜欢这个。我需要他们两个。如果我去intptr,它不能转换为int,所以postmessage等东西失败,其他方式,需要“处理”的东西失败,因为它应该是指针。

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

我基本上想要执行此操作同时使用我的int findwindow函数。任何想法怎么样? Findwindow也是句柄,对吗?

1 个答案:

答案 0 :(得分:2)

使用返回int的版本永远不正确。 FindWindow返回一个窗口句柄,它始终是IntPtr。您需要修改PostMessage声明:

[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);