Jump to content

WinAPI CreateCompatibleBitmap: The specified module could not be found.


Recommended Posts

Hi,

I am getting the following error message after running Autoit script.

WinAPI CreateCompatibleBitmap: The specified module could not be found.

In my script I am using Autoit function "_ScreenCapture_Capture".

After saving approximately 900 images, we are getting the error message "WinAPI CreateCompatibleBitmap: The specified module could not be found." and Autoit script starts running.

Because of this problem our script is running for around 5 hours and stops. But our intention is to execute the script, without stopping in the middle.

please provide solution to this problem, so that our script efficiency will increase.

Link to comment
Share on other sites

Hi,

I am getting the following error message after running Autoit script.

WinAPI CreateCompatibleBitmap: The specified module could not be found.

In my script I am using Autoit function "_ScreenCapture_Capture".

After saving approximately 900 images, we are getting the error message "WinAPI CreateCompatibleBitmap: The specified module could not be found." and Autoit script starts running.

Because of this problem our script is running for around 5 hours and stops. But our intention is to execute the script, without stopping in the middle.

please provide solution to this problem, so that our script efficiency will increase.

You do not accidentally forget about _WinAPI_DeleteObject()?
Link to comment
Share on other sites

You do not accidentally forget about _WinAPI_DeleteObject()?

Hi,

It is taken care in the following library function available under "Include" folder in istallation directory.

_ScreenCapture_Capture. This function is available in ScreenCapture.au3.

Link to comment
Share on other sites

It's a bug. You can submit it (do that really).

Your script will brake because of leaking GDI objects. Replace current _ScreenCapture_Capture() with this one and you will be ok:

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_DestroyIcon($hIcon)
            _WinAPI_DeleteObject($aIcon[4]); <- THIS!
            _WinAPI_DeleteObject($aIcon[5]); <- THIS!
        EndIf
    EndIf

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

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

The problem is related to the cursor (I've made a comment pointing to it in the fixed function). Reference is this (remarks section).

Link to comment
Share on other sites

It's a bug. You can submit it (do that really).

Your script will brake because of leaking GDI objects. Replace current _ScreenCapture_Capture() with this one and you will be ok:

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_DestroyIcon($hIcon)
            _WinAPI_DeleteObject($aIcon[4]); <- THIS!
            _WinAPI_DeleteObject($aIcon[5]); <- THIS!
        EndIf
    EndIf

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

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

The problem is related to the cursor (I've made a comment pointing to it in the fixed function). Reference is this (remarks section).

Hi,

Thank you, very much.

How to log a defect?

We will test and get back.

Link to comment
Share on other sites

It's a bug. You can submit it (do that really).

Your script will brake because of leaking GDI objects. Replace current _ScreenCapture_Capture() with this one and you will be ok:

The problem is related to the cursor (I've made a comment pointing to it in the fixed function). Reference is this (remarks section).

trancexx

Well found.

Another "reference to this" is the AutoIt help file under _WinAPI_GetIconInfo.

Link to comment
Share on other sites

I submitted this bug to Trac 2 weeks ago, and it's fixed in version: 3.3.1.2

_ScreenCapture_Capture(): GDI object leak with cursor capture

Ticket:#1040

Hi,

Sorry. Without the awareness of your bug, I have added a new bug.

Thank you.

Link to comment
Share on other sites

  • 6 months later...

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...