Hi everyone,

I'm trying to use GetDIBits to convert a DDB to DIB.
I'm having a problem with GetDIBits. When i include a pointer to receive the bitmap data, the function fails and i get a return of 0.
Where did i go wrong with my code? :confused:

Thanks in advance! :alright:

CODE:
_________________________________________________________________________________________________________________

PrintSetUp proc hWnd:HWND, hDC:DWORD

local tmpval :DWORD
local memDC :DWORD
local cmpBM :DWORD
local cmpDC :DWORD
local s_logpixx :DWORD
local s_logpixy :DWORD
local d_logpixx :DWORD
local d_logpixy :DWORD
local prvObj :DWORD
local retVal :DWORD
local pixels :DWORD
local rgbq :RGBQUAD

invoke GetDC, hWnd
.if eax == 0
invoke MessageBox,NULL,ADDR GetDC_error,OFFSET AppName,MB_OK
.else
mov memDC, eax
.endif

invoke CreateCompatibleDC, memDC
.if eax == 0
invoke MessageBox,NULL,ADDR CreateCompatibleDC_error,OFFSET AppName,MB_OK
.else
mov cmpDC, eax
.endif

invoke GetDeviceCaps, memDC, LOGPIXELSX
mov s_logpixx, eax

invoke GetDeviceCaps, memDC, LOGPIXELSY
mov s_logpixy, eax

mov tmpval, 4
push sizeof BITMAPINFOHEADER
pop bInfo.bmiHeader.biSize
push bmWidth
pop bInfo.bmiHeader.biWidth
push bmHeight
pop bInfo.bmiHeader.biHeight
mov bInfo.bmiHeader.biPlanes, 1
mov eax, 24
mov bInfo.bmiHeader.biBitCount, ax
mov bInfo.bmiHeader.biCompression, BI_RGB

fild bmWidth
fild bmHeight
fmul
fild tmpval
fmul
fistp tmpval
push tmpval
pop bInfo.bmiHeader.biSizeImage
mov bInfo.bmiHeader.biXPelsPerMeter, 0
mov bInfo.bmiHeader.biYPelsPerMeter, 0
mov bInfo.bmiHeader.biClrUsed, 0
mov bInfo.bmiHeader.biClrImportant, 0

invoke SelectObject, cmpDC, hBitmap;cmpBM
.if eax == 0
invoke MessageBox,NULL,ADDR SelectObject_error,OFFSET AppName,MB_OK
invoke GetLastError
push eax
pop ecx
invoke NumberToString, ecx
invoke MessageBox,NULL,ADDR StrNumBuf,OFFSET AppName,MB_OK
.else
mov prvObj, eax
.endif

invoke BitBlt, cmpDC, 400, 0, bmWidth, bmHeight, memDC, 0, 0, SRCCOPY
.if eax == 0
invoke MessageBox,NULL,ADDR BitBlt_error,OFFSET AppName,MB_OK
invoke GetLastError
push eax
pop ecx
invoke NumberToString, ecx
invoke MessageBox,NULL,ADDR StrNumBuf,OFFSET AppName,MB_OK
.else
mov retVal, eax
.endif

invoke GetDIBits, cmpDC, hBitmap, 0, bmHeight, NULL, addr bInfo, DIB_RGB_COLORS
.if eax == 0
invoke MessageBox,NULL,ADDR GetDIBits_error,OFFSET AppName,MB_OK
invoke GetLastError
push eax
pop ecx
invoke NumberToString, ecx
invoke MessageBox,NULL,ADDR StrNumBuf,OFFSET AppName,MB_OK
.else
mov retVal, eax
.endif

invoke GetDIBits, cmpDC, hBitmap, 0, bmHeight, addr pixels, addr bInfo, DIB_RGB_COLORS
.if eax == 0
invoke MessageBox,NULL,ADDR GetDIBits_error,OFFSET AppName,MB_OK
invoke GetLastError
push eax
pop ecx
invoke NumberToString, ecx
invoke MessageBox,NULL,ADDR StrNumBuf,OFFSET AppName,MB_OK
.else
mov retVal, eax
.endif

invoke StretchDIBits,memDC,500,0,bmWidth,bmHeight,0,0,bmWidth,bmHeight,pixels,ADDR bInfo,DIB_RGB_COLORS,SRCCOPY
.if eax == 0
invoke MessageBox,NULL,ADDR StretchDIBits_error,OFFSET AppName,MB_OK
invoke GetLastError
push eax
pop ecx
invoke NumberToString, ecx
invoke MessageBox,NULL,ADDR StrNumBuf,OFFSET AppName,MB_OK
.endif

invoke DeleteDC,cmpDC
invoke DeleteDC,memDC
ret
PrintSetUp endp
_________________________________________________________________________________________________________________
Posted on 2003-10-29 02:29:06 by trexxz
ok. i have managed to solve the GetDIBits error. But now, my StretchDIBits give me an error.. (returns 0)

CODE:
PrintSetUp proc hWnd:HWND, hDC:DWORD

local tmpval :DWORD
local memDC :DWORD
local cmpBM :DWORD
local cmpDC :DWORD
local s_logpixx :DWORD
local s_logpixy :DWORD
local d_logpixx :DWORD
local d_logpixy :DWORD
local prvObj :DWORD
local retVal :DWORD
local pixels :DWORD
local rgbq :RGBQUAD

invoke GetDC, hWnd
.if eax == 0
invoke MessageBox,NULL,ADDR GetDC_error,OFFSET AppName,MB_OK
.else
mov memDC, eax
.endif

invoke CreateCompatibleDC, memDC
.if eax == 0
invoke MessageBox,NULL,ADDR CreateCompatibleDC_error,OFFSET AppName,MB_OK
.else
mov cmpDC, eax
.endif

invoke CreateCompatibleBitmap, memDC, 334, 207
.if eax == 0
invoke MessageBox,NULL,ADDR CreateCompatibleBitmap_error,OFFSET AppName,MB_OK
.else
mov cmpBM, eax
.endif

invoke GetDeviceCaps, memDC, LOGPIXELSX
mov s_logpixx, eax

invoke GetDeviceCaps, memDC, LOGPIXELSY
mov s_logpixy, eax

mov tmpval, 4
push sizeof BITMAPINFOHEADER
pop bInfo.bmiHeader.biSize
push bmWidth
pop bInfo.bmiHeader.biWidth
push bmHeight
pop bInfo.bmiHeader.biHeight
mov bInfo.bmiHeader.biPlanes, 1
mov eax, 24
mov bInfo.bmiHeader.biBitCount, ax
mov bInfo.bmiHeader.biCompression, BI_RGB

fild bmWidth
fild bmHeight
fmul
fild tmpval
fmul
fistp tmpval
push tmpval
pop bInfo.bmiHeader.biSizeImage
mov bInfo.bmiHeader.biXPelsPerMeter, 0
mov bInfo.bmiHeader.biYPelsPerMeter, 0
mov bInfo.bmiHeader.biClrUsed, 0
mov bInfo.bmiHeader.biClrImportant, 0

invoke SelectObject, cmpDC, cmpBM ;hBitmap
.if eax == 0
invoke MessageBox,NULL,ADDR SelectObject_error,OFFSET AppName,MB_OK
invoke GetLastError
push eax
pop ecx
invoke NumberToString, ecx
invoke MessageBox,NULL,ADDR StrNumBuf,OFFSET AppName,MB_OK
.else
mov prvObj, eax
.endif

invoke BitBlt, cmpDC, 400, 0, bmWidth, bmHeight, memDC, 0, 0, SRCCOPY
.if eax == 0
invoke MessageBox,NULL,ADDR BitBlt_error,OFFSET AppName,MB_OK
invoke GetLastError
push eax
pop ecx
invoke NumberToString, ecx
invoke MessageBox,NULL,ADDR StrNumBuf,OFFSET AppName,MB_OK
.else
mov retVal, eax
.endif

invoke GetDIBits, cmpDC, cmpBM, 0, bmHeight, NULL, addr bInfo, DIB_RGB_COLORS
.if eax == 0
invoke MessageBox,NULL,ADDR GetDIBits_error,OFFSET AppName,MB_OK
invoke GetLastError
push eax
pop ecx
invoke NumberToString, ecx
invoke MessageBox,NULL,ADDR StrNumBuf,OFFSET AppName,MB_OK
.else
mov retVal, eax
.endif

invoke GetDIBits, cmpDC, cmpBM, 0, bmHeight, pixels, addr bInfo, DIB_RGB_COLORS
.if eax == 0
invoke MessageBox,NULL,ADDR GetDIBits_error,OFFSET AppName,MB_OK
invoke GetLastError
push eax
pop ecx
invoke NumberToString, ecx
invoke MessageBox,NULL,ADDR StrNumBuf,OFFSET AppName,MB_OK
.else
mov retVal, eax
.endif

lea ebx, pixels

invoke StretchDIBits,memDC,500,0,bmWidth,bmHeight,0,0,bmWidth,bmHeight,ebx,ADDR bInfo,DIB_RGB_COLORS,SRCCOPY
.if eax == 0
invoke MessageBox,NULL,ADDR StretchDIBits_error,OFFSET AppName,MB_OK
invoke GetLastError
push eax
pop ecx
invoke NumberToString, ecx
invoke MessageBox,NULL,ADDR StrNumBuf,OFFSET AppName,MB_OK
.endif

invoke DeleteDC,cmpDC
invoke DeleteDC,memDC
ret
PrintSetUp endp
Posted on 2003-10-29 03:03:31 by trexxz