Jump to content

Procedure not found with DLLCall to GetPixel


klf92
 Share

Recommended Posts

I am having trouble with using DLLCall to GetPixel to get the pixel color of pixels on nonactive / covered / hidden windows. I just modified the useful to look for Pixels instead, and it's quite handy.

Sometimes however after the DLLCall _WinAPI_GetLastError() returns 127, which is "The specified procedure could not be found." I also sometimes get error 5, which is "Access is Denied." When this happens the pixel color is still returned correctly, so I can't figure out why the errors are happening, or what I can do to fix them. (The grey color 333333 as shown in the errors below is the typical non target color found.) The errors do not happen consistently or with particular parameters - I can discern no pattern (although this doesn't mean one does not exist).

Any advice is appreciated, thank you.

$targetCoord is an 2d array with a list of coordinates to try clicking on, the rest should be clear I hope.

Func _findTargetPixel(ByRef $tHnd, ByRef $targetCoord, $targetPixelColor)
    local $h = _WinAPI_GetWindowHeight($tHnd)
    local $w = _WinAPI_GetWindowWidth($tHnd)
 
    local $hDC = _WinAPI_GetWindowDC($tHnd)
    if not $hDC then
        MsgBox(0, "hDC", _WinAPI_GetLastError())
        return 0
    EndIf
    
    local $hdcMem = _WinAPI_CreateCompatibleDC($hDC)
    if not $hdcMem then
        MsgBox(0, "hdcMem", _WinAPI_GetLastError())
    return 0
    EndIf
    
    local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
    if not $hBmp then
        MsgBox(0, "hBmp", _WinAPI_GetLastError())
        return 0
    EndIf
    
    local $hOld = _WinAPI_SelectObject($hdcMem, $hBmp)
 
    For $i = 0 to UBound($targetCoord) - 1
        _WinAPI_SetLastError(0)
        Local $result = DLLCall("gdi32", "int", "GetPixel", "ptr", $hDC, "int", $targetCoord[$i][0], "int", $targetCoord[$i][1])
        if @error or _WinAPI_GetLastError() then
             MsgBox(0, "Error", "Error in _GetPixelColor" & @CR & "AutoIT @error " & @error & @CR & _WinAPI_GetLastError() & _WinAPI_GetLastErrorMessage() & @CR & "Found Color " & Hex($result[0],6) & @CR)
         EndIF
            _WinAPI_ReleaseDC($tHnd, $hDC)
            If $result[0] = $targetPixelColor Then
                return $i
            Else
                return -2
            EndIF
        EndIf
        If $result[0] = $targetPixelColor Then
            _WinAPI_ReleaseDC($tHnd, $hDC)
            return $i ; target found in position $i
        EndIf
    Next
            
    _WinAPI_ReleaseDC($tHnd, $hDC)
    return -1
EndFunc

Posted Image

Posted Image

Link to comment
Share on other sites

Hi Manadar,

Thanks for your reply. I made this change to my code of gdi32->gdi32.dll and also explicitly using DLLOpen and DLLClose. This did not eliminate the errors. I was also aware of your function, since I searched beforehand, but I couldn't see how to easily make it work on non-active/obscured windows, whereas the very similar method I use now does that. Your method takes a screen capture, and I want my function to work on pixels that aren't seen when the screen is captured. If you think that some difference between the two is causing the problem I would appreciate an explanation, since I still do not understand the cause of my problem.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...