Hackhers

How to save bitmap inside dll (or load as HBitMap)

6 posts in this topic

Hello, I'm trying to get bitmap image from DLL and load as HBitMap image but cant figure out how. So I tried to save it but still no luck. 

Here is dll, if you can give the load as hBitMap it will be the best ! :)

 

#RequireAdmin
#include <APIMiscConstants.au3>
#include <APIResConstants.au3>
#include <GUIConstantsEx.au3>
#include <Memory.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WinAPIMisc.au3>
#include <WinAPIRes.au3>


Local Const $sJpg = @ScriptDir & '\sest.bmp'

; Load Resources.dll to memory
Local $hInstance = _WinAPI_LoadLibraryEx(@ScriptDir & '\TestServer.dll', $LOAD_LIBRARY_AS_DATAFILE)
If Not $hInstance Then
    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', @ScriptDir & '\TestServer.dll')
    Exit
EndIf

; Load JPEG resource from Resources.dll library

Local $hResource = _WinAPI_FindResource($hInstance, 2, 106 )
Local $iSize = _WinAPI_SizeOfResource($hInstance, $hResource)
Local $hData = _WinAPI_LoadResource($hInstance, $hResource)
Local $pData = _WinAPI_LockResource($hData)


MsgBox(0, default, "!" & $iSize &  "!" & $hData & "!"  )

; Save resource to .bmp file
Local $hFile = FileOpen($sJpg, 2 + 16)
Local $tData = DllStructCreate('byte[' & $iSize & ']', $pData)
FileWrite($hFile, DllStructGetData($tData, 1))
FileClose($hFile)

 

TestServer.dll

Share this post


Link to post
Share on other sites



HI.

$gui = GUICreate("")
$pic = GUICtrlCreatePic("",0,0,200,200)

GUISetState()

SetBitmapResourceToPicCtrl($gui,$pic,"C:\Users\Usuario\Downloads\TestServer.dll",101)

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

Func SetBitmapResourceToPicCtrl($hwnd,$ctrl,$file,$resource)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $LR_CREATEDIBSECTION = 0x2000
    Local $A = ControlGetHandle($hwnd,"",$ctrl)
    Local $DLLinst = DLLCall("kernel32.dll","hwnd","LoadLibrary","str",$file)
    $DLLinst = $DLLinst[0]
    Local $hBitmap = DLLCall("user32.dll","hwnd","LoadImage","hwnd",$DLLinst,"short",$resource, _
            "int",$IMAGE_BITMAP,"int",0,"int",0,"int",0)
    $hBitmap = $hBitmap[0]
    _SendMessage($A,$STM_SETIMAGE,$IMAGE_BITMAP,$hBitmap);
    DLLCall("gdi32.dll","int","DeleteObject","hwnd",$hBitmap)
    DLLCall("kernel32.dll","int","FreeLibrary","hwnd",$DLLinst)
EndFunc

Func _SendMessage($hWnd, $msg, $wParam = 0, $lParam = 0, $r = 0, $t1 = "int", $t2 = "int")
    Local $ret = DllCall("user32.dll", "long", "SendMessage", "hwnd", $hWnd, "int", $msg, $t1, $wParam, $t2, $lParam)
    If @error Then Return SetError(@error, @extended, "")
    If $r >= 0 And $r <= 4 Then Return $ret[$r]
    Return $ret
EndFunc ; _SendMessage()

Saludos

Share this post


Link to post
Share on other sites

HI.

$gui = GUICreate("")
$pic = GUICtrlCreatePic("",0,0,200,200)

GUISetState()

SetBitmapResourceToPicCtrl($gui,$pic,"C:\Users\Usuario\Downloads\TestServer.dll",101)

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

Func SetBitmapResourceToPicCtrl($hwnd,$ctrl,$file,$resource)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $LR_CREATEDIBSECTION = 0x2000
    Local $A = ControlGetHandle($hwnd,"",$ctrl)
    Local $DLLinst = DLLCall("kernel32.dll","hwnd","LoadLibrary","str",$file)
    $DLLinst = $DLLinst[0]
    Local $hBitmap = DLLCall("user32.dll","hwnd","LoadImage","hwnd",$DLLinst,"short",$resource, _
            "int",$IMAGE_BITMAP,"int",0,"int",0,"int",0)
    $hBitmap = $hBitmap[0]
    _SendMessage($A,$STM_SETIMAGE,$IMAGE_BITMAP,$hBitmap);
    DLLCall("gdi32.dll","int","DeleteObject","hwnd",$hBitmap)
    DLLCall("kernel32.dll","int","FreeLibrary","hwnd",$DLLinst)
EndFunc

Func _SendMessage($hWnd, $msg, $wParam = 0, $lParam = 0, $r = 0, $t1 = "int", $t2 = "int")
    Local $ret = DllCall("user32.dll", "long", "SendMessage", "hwnd", $hWnd, "int", $msg, $t1, $wParam, $t2, $lParam)
    If @error Then Return SetError(@error, @extended, "")
    If $r >= 0 And $r <= 4 Then Return $ret[$r]
    Return $ret
EndFunc ; _SendMessage()

Saludos


Thank you so much for response, but I dont want to show it on GUI can you please make it return as 
hHBitmap ?

(Sorry if It's silly question I'm kinda confused)

Share this post


Link to post
Share on other sites
$hBitmap[0]

 

Saludos

Thank you !

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