Jump to content
Sign in to follow this  

Memory leak in _ScreenCapture_Capture ?

Recommended Posts


If I run _ScreenCapture_Capture continually for about an hour or two strait I receive various errors like "WinAPI error collecting Device Context" or "WinAPI error handle provided is invalid". I believe these errors were being caused by a memory leak or similar problem.

To correct this issue add the following lines to the bottom of _ScreenCapture_Capture

    _WinAPI_DestroyIcon($hIcon)oÝ÷ Ù8b²+-ç.®·§¶Ç+H«Þm秺ȧZ½ëÞ®'âyØ­Âä³­zºk¥jدyê뢻¢»©×hhº»!j÷§ßÛaiÖ§¢h®Û§Ü­¢×¬µú+àz¶®¶­s`Æö6Âb33c¶Âb33c¶rÂb33c¶væBÂb33c¶DD2Âb33c¶4D2Âb33c¶$ÕÂb33c¶7W'6÷"Âb33c¶6öâÂb33c¶6öà  bb33c¶&vBÒÓFVâb33c¶&vBÒõväôvWE77FVÔÖWG&72b33cµ4Õô545$TTâ bb33c¶&÷GFöÒÒÓFVâb33c¶&÷GFöÒÒõväôvWE77FVÔÖWG&72b33cµ4Õô545$TTâ bb33c¶&vBfÇC²b33c¶ÆVgBFVâ&WGW&â6WDW'&÷"Ó bb33c¶&÷GFöÒfÇC²b33c¶F÷FVâ&WGW&â6WDW'&÷"Ó"  b33c¶rÒb33c¶&vBÒb33c¶ÆVg@ b33c¶Òb33c¶&÷GFöÒÒb33c¶F÷ b33c¶væBÒõväôvWDFW6·F÷væF÷r b33c¶DD2ÒõväôvWDD2b33c¶væB b33c¶4D2Òõväô7&VFT6ö×F&ÆTD2b33c¶DD2 b33c¶$ÕÒõväô7&VFT6ö×F&ÆT&FÖb33c¶DD2Âb33c¶rÂb33c¶ õväõ6VÆV7Dö&¦V7Bb33c¶4D2Âb33c¶$Õ õväô&D&ÇBb33c¶4D2ÂÂÂb33c¶rÂb33c¶Âb33c¶DD2Âb33c¶ÆVgBÂb33c¶F÷Âb33cµ5$44õ  bb33c¶d7W'6÷"FVà b33c¶7W'6÷"ÒõväôvWD7W'6÷$æfò bb33c¶7W'6÷%³ÒFVà b33c¶6öâÒõväô6÷6öâb33c¶7W'6÷%³%Ò b33c¶6öâÒõväôvWD6öäæfòb33c¶6öâ õväôG&t6öâb33c¶4D2Âb33c¶7W'6÷%³5ÒÒb33c¶6öå³%ÒÂb33c¶7W'6÷%³EÒÒb33c¶6öå³5ÒÂb33c¶6öâ VæD` VæD`  õväõ&VÆV6TD2b33c¶væBÂb33c¶DD2 õväôFVÆWFTD2b33c¶4D2 bb33c·4fÆTæÖRÒgV÷C²gV÷C²FVâ&WGW&âb33c¶$Õ õ67&VVä6GW&Uõ6fTÖvRb33c·4fÆTæÖRÂb33c¶$Õ õväôFVÆWFTö&¦V7Bb33c¶$Õ õväôFW7G&÷6öâb33c¶6öâ

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Share this post

Link to post
Share on other sites

Func _ScreenCapture_Capture($sFileName = "", $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = True)
    Local $iH, $iW, $hWnd, $hDDC, $hCDC, $hBMP, $aCursor, $aIcon, $hIcon

    If $iRight = -1 Then $iRight = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CXSCREEN)
    If $iBottom = -1 Then $iBottom = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN)
    If $iRight < $iLeft Then Return SetError(-1, 0, 0)
    If $iBottom < $iTop Then Return SetError(-2, 0, 0)

    $iW = $iRight - $iLeft
    $iH = $iBottom - $iTop
    $hWnd = _WinAPI_GetDesktopWindow()
    $hDDC = _WinAPI_GetDC($hWnd)
    $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH)
    _WinAPI_SelectObject($hCDC, $hBMP)
    _WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, $__SCREENCAPTURECONSTANT_SRCCOPY)

    If $fCursor Then
        $aCursor = _WinAPI_GetCursorInfo()
        If $aCursor[1] Then
            $hIcon = _WinAPI_CopyIcon($aCursor[2])
            $aIcon = _WinAPI_GetIconInfo($hIcon)
            _WinAPI_DrawIcon($hCDC, $aCursor[3] - $aIcon[2] - $iLeft, $aCursor[4] - $aIcon[3] - $iTop, $hIcon)

    _WinAPI_ReleaseDC($hWnd, $hDDC)
    If $sFileName = "" Then Return $hBMP

    _ScreenCapture_SaveImage($sFileName, $hBMP)
EndFunc   ;==>_ScreenCapture_Capture

SciTE for AutoItDirections for Submitting Standard UDFs


Don't argue with an idiot; people watching may not be able to tell the difference.


Share this post

Link to post
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
Sign in to follow this