Ok, I am trying to read a single pixel's color from another application.

I have used GetPixel before (way back with VB6). However, this time around, I can't get it to read correctly!

Here is what I am TRYING to do:

1. Get target window handle (hWnd) using FindWindow()
2. Get device context (hDC) of window using GetDC(hwnd)
3. Get Pixel color using GetPixel(hdc, x, y)
4. ReleaseDC()


However, GetPixel never returns a color. It either returns 'FFFFFF', 0, or -1.

I don't know if it's my declarations, or what I'm doing wrong. I have been able to declare and use other API functions just fine- I just can't figure out how to get GetPixel() to work properly!

I'm using VB.net / Visual Studio 2005. Here is the code that is in question:
Code:
Code:
    Declare Auto Function FindWindow Lib "user32" ( _
      ByVal lpClassName As String, _
      ByVal lpWindowName As String) As IntPtr

    Declare Function GetDC Lib "user32" (ByVal hWnd As IntPtr) As IntPtr
    Declare Function ReleaseDC Lib "user32" (ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr

    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As IntPtr, ByVal X As Int32, ByVal Y As Int32) As Int32

    Public Function GetColorAt(ByVal X As Int32, ByVal Y As Int32) As Int32

        Dim hWnd As IntPtr
        Dim hDC As IntPtr

        hWnd = FindWindow(vbNullString, "RagII")

        hDC = GetDC(hWnd)

        Dim lColor As Int32 = GetPixel(hDC, X, Y)  

        ReleaseDC(hWnd, hDC)

        Return lColor
    End Function
Does anyone know what I'm doing wrong?

Thanks in advance,
P.dub