Pelles C forum

Assembly language => Assembly discussions => Topic started by: Vortex on July 11, 2026, 10:54:05 PM

Title: Saving a bitmap from handle
Post by: Vortex on July 11, 2026, 10:54:05 PM
SaveBmpFromHBitmap function creating and saving a bitmap represented by the handle. The example code below loads a bitmap and recreates it with SaveBmpFromHBitmap.

.386
.model flat,stdcall
option casemap:none

include     Example.inc

includelib  kernel32.lib
includelib  user32.lib
includelib  gdi32.lib

SaveBmpFromHBitmap PROTO :DWORD,:DWORD

.data

BmpFile     db 'Sample.bmp',0
filename    db 'TestBitmap.bmp',0

.data?

hBitmap     dd ?

.code

start:

    xor     eax,eax
    invoke  LoadImage,eax,ADDR BmpFile,\
            IMAGE_BITMAP,eax,eax,LR_LOADFROMFILE

    test    eax,eax
    jz      @f
    mov     hBitmap,eax

    invoke  SaveBmpFromHBitmap,eax,ADDR filename
@@:
    invoke  DeleteObject,hBitmap
    invoke  ExitProcess,0

END start