Jump to content
Sign in to follow this  

from a bitmap handle to the address in memory?

Recommended Posts


If I've got the handle to a bitmap object, is it possible to get the starting (global memory) address of the bitmap?

... or can I move it to an address where I can read it from an external programm?

What I did untill yet:

$pointer = _MemGlobalLock($hBitmap)

and export the pointer to a different process. this gave me errors and wrong content >_< .

This would mean, that the handle of the bitmap is a global memory object .... or is it not?

i'm quite desperate,


ps.: What is the best way to share memory over two processes?

Share this post

Link to post
Share on other sites

... no answers, maybe the question is not clear:

The goal is to make very fast screen shots and let them be read from an external program (lisp) for

pattern recognition.

after some hours of work I found the post of siao:


that helped me a lot:

now i'm able to to copy a screenshot (bitmap) to a dellstruct (20 ms for the hole screen). but one error remeans:

even using nomadmemory, i can not access the data with the pointer of the dllstruct: DllStructGetPtr($tBits)

from a different application.

#include <WinAPI.au3>
#include <ScreenCapture.au3>
#Include <Array.au3>
#Include <nomadmemory.au3>

; open memory:
$ah_Handle = _MemoryOpen(_WinAPI_GetCurrentProcessID())
$time = TimerInit()

$iWidth = 16; @DesktopWidth
$iHeight = 16; @DesktopHeight
$iBitCount = 24
$hBmp = _ScreenCapture_Capture("", 0, 0, $iWidth, $iHeight)

$tBMI = DllStructCreate($tagBITMAPINFO)
        DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
        DllStructSetData($tBMI, "Width", $iWidth)
        DllStructSetData($tBMI, "Height", -$iHeight)
        DllStructSetData($tBMI, "Planes", 1)
        DllStructSetData($tBMI, "BitCount", $iBitCount)
 $hDC = _WinAPI_GetDC(0)

$hCDC = _WinAPI_CreateCompatibleDC($hDC)
$aDIB = DllCall('gdi32.dll','ptr','CreateDIBSection', 'ptr',0, 'ptr',DllStructGetPtr($tBMI) , 'uint',$DIB_RGB_COLORS , 'ptr*',0, 'ptr',0, 'uint',0)

; select object 
_WinAPI_SelectObject($hCDC, $aDIB[0])

; copy the content of the bitmap into the buffer ...
_WinAPI_GetDIBits($hDC, $hBmp, 0, $iHeight, $aDIB[4], DllStructGetPtr($tBMI), $DIB_RGB_COLORS)

; create the a dllstruct with the pointer $aDIB[4]
$tBits = DllStructCreate('byte[' & $iWidth*$iHeight*$iBitCount/8 & ']', $aDIB[4])

; view the beasts ...
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : TimerDiff($time) = ' & TimerDiff($time) & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aDIB[4] = ' & $aDIB[4] & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $tBits = ' & $tBits & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
; use this pointer!!!!
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : DllStructGetPtr($tBits) = ' & DllStructGetPtr($tBits) & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console


; view the pixels as string:
$sHex = Hex(DllStructGetData($tBits, 1))
MsgBox(0, '', $sHex)

; releasing ...
_WinAPI_SelectObject($hCDC, $aDIB[0])
_WinAPI_ReleaseDC(0, $hDC)

; close the memory
 $rgw = _MemoryClose($ah_Handle)
 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $rgw = ' & $rgw & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console


in lisp i always get this error: exception_access_violation. means that wrong pointer???

... maybe i've some tomato on my eyes, maybe somone can help,


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