flat assembler
Message board for the users of flat assembler.

Index > Windows > Why CreateDIBSection() returns NULL?

Author
Thread Post new topic Reply to topic
programmer



Joined: 05 Jun 2006
Posts: 6
programmer 19 Jun 2006, 11:38
I can't get it work.

Code:
--- data section ---
infoheader BITMAPINFOHEADER 40,581,381,1,24,BI_RGB,0,0,0,0,0
bminfo BITMAPINFO
winDC dd ?
memDC dd ?
hbitmap dd ?
bmsize dd ?
bmbits dd ?
...

--- code section ---
... some code ...

invoke GetWindowDC,[hMain] ; hMain is a handle to main window
mov [winDC],eax

invoke CreateCompatibleDC,[winDC]
mov [memDC],eax

mov eax,[infoheader]
mov [bminfo.bmiHeader],eax

invoke CreateDIBSection,[memDC],bminfo,0,bmbits,0,0
mov [hbitmap],eax

... more code ...
...
    
Why [hbitmap] is NULL?
Post 19 Jun 2006, 11:38
View user's profile Send private message Reply with quote
Lion17



Joined: 30 May 2006
Posts: 5
Lion17 19 Jun 2006, 11:46
replace code
Code:
infoheader BITMAPINFOHEADER 40,581,381,1,24,BI_RGB,0,0,0,0,0 
bminfo BITMAPINFO    

with
Code:
bminfo:
infoheader BITMAPINFOHEADER 40,581,381,1,24,BI_RGB,0,0,0,0,0 
    

delete code
Code:
mov eax,[infoheader] 
mov [bminfo.bmiHeader],eax    
Post 19 Jun 2006, 11:46
View user's profile Send private message ICQ Number Reply with quote
programmer



Joined: 05 Jun 2006
Posts: 6
programmer 19 Jun 2006, 11:59
Thanks!
I'm trying to save bitmap from DC to file, but it doesn't work anyway. Please help me.
Code:
fileheader BITMAPFILEHEADER 0x4D42,0,0,0,54
bminfo:
infoheader BITMAPINFOHEADER 40,581,381,1,24,BI_RGB,0,0,0,0,0
;bminfo BITMAPINFO
nobw dd ?
winDC dd ?
memDC dd ?
hbitmap dd ?
bmsize dd ?
hfile dd ?
                
bmbits dd ?
        
        proc SaveBitmapToFile
                
                ;mov eax,[infoheader]
                ;mov [bminfo.bmiHeader],eax
                
                invoke GetWindowDC,[hPicDisp]
                mov [winDC],eax
                
                invoke CreateCompatibleDC,[winDC]
                mov [memDC],eax
                
                invoke CreateDIBSection,[winDC],bminfo,0,bmbits,0,0
                mov [hbitmap],eax
                
                invoke SelectObject,[memDC],[hbitmap]
                
                invoke BitBlt,[memDC],0,0,581,381,[winDC],0,0,SRCCOPY
                
                invoke DeleteDC,[memDC]
                
                invoke ReleaseDC,[hPicDisp],[winDC]
                
                invoke CreateFile,'C:\screen.bmp',GENERIC_READ + GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
                mov [hfile],eax
                
                invoke WriteFile,[hfile],fileheader,14,nobw,0
                invoke WriteFile,[hfile],infoheader,40,nobw,0
                
                ;((biWidth * (biBitCount / 8) + 3) And &HFFFFFFFC) * biHeight
                mov eax,24
                ;mov ebx,8
                ;div ebx
                shr eax,3
                mov ebx,[infoheader.biWidth]
                mul ebx
                add eax,3
                and eax,0xFFFFFFFC
                mov ebx,[infoheader.biHeight]
                mul ebx
                
                
                invoke WriteFile,[hfile],bmbits,eax,nobw,0
                
                invoke CloseHandle,[hfile]
                
                invoke DeleteObject,[hbitmap]
                
                ret
        endp
    
Post 19 Jun 2006, 11:59
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.