GetDIBits works on Win2K not Win98? 
Author Message
 GetDIBits works on Win2K not Win98?

The following code runs on my Win2k machine fine, the BITMAPINFO structure
is populated by GetDIBits just fine. But the exact same code on my Win98
machine shows a GetDIBits returns 0; and Err.LastDllError shows 87 (Invalid
Param). Can anybody see what I am doing wrong, or does anybody know why it
is acting this way? Any help appreciated. Thanks.

    ' load the bmp, get handle
    Dim hBmp As Long
    hBmp = LoadImage(0, "c:\temp\stone.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
    Debug.Print "hBmp:", hBmp

    ' create dc
    Dim hdc As Long
    hdc = CreateCompatibleDC(0)
    Debug.Print "hDC:", hdc

    ' select bmp into dc
    Dim hBmp0
    hBmp0 = SelectObject(hdc, hBmp)

    ' get some bitmap information
    Dim bmp As BITMAP
    GetObjectAPI hBmp, Len(bmp), bmp
    Debug.Print bmp.bmWidth & "x" & bmp.bmHeight, bmp.bmBitsPixel,
bmp.bmWidthBytes

    Dim bi As BITMAPINFO
    bi.bmiHeader.biSize = Len(bi)
    Debug.Print GetDIBits(hdc, hBmp, 0, 0, 0, bi, 0)
    Debug.Print Err.LastDllError
    Debug.Print bi.bmiHeader.biHeight & "x" & bi.bmiHeader.biWidth,
bi.bmiHeader.biBitCount, bi.bmiHeader.biSizeImage

(I actually call GetDIBits twice, first to get the structure, second to get
the byte array)



Tue, 08 Feb 2005 20:43:34 GMT  
 GetDIBits works on Win2K not Win98?
Hi DB,

The parameter that you are passing for biSize is incorrect.

The following line:

 bi.bmiHeader.biSize =  Len(bi)

should be changed to:

 bi.bmiHeader.biSize = Len(bi.bmiHeader)    
Or you can hardcode it to 40. Not sure how it worked in win2000 though.

Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.              



Wed, 09 Feb 2005 05:59:58 GMT  
 GetDIBits works on Win2K not Win98?
Thanks for catching that, although when I did change it, it still fails on
Win98, any other ideas?
thanks.



Quote:
> Hi DB,

> The parameter that you are passing for biSize is incorrect.

> The following line:

>  bi.bmiHeader.biSize =  Len(bi)

> should be changed to:

>  bi.bmiHeader.biSize = Len(bi.bmiHeader)
> Or you can hardcode it to 40. Not sure how it worked in win2000 though.

> Hope this helps!
> Bharat Patel
> Microsoft, Visual Basic .NET

> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Please reply to newsgroups only. Thanks.



Fri, 11 Feb 2005 20:26:27 GMT  
 GetDIBits works on Win2K not Win98?
Hi DB,

Here is the code sample with all Declares. I tested it out on Win98 and it
worked fine. Can you check this out:

'==========================================================
Const IMAGE_BITMAP = &O0
Const LR_LOADFROMFILE = &H10
Const LR_DEFAULTSIZE = &H40
Const LR_CREATEDIBSECTION = &H2000

Private Type BITMAPINFOHEADER
       biSize As Long
       biWidth As Long
       biHeight As Long
       biPlanes As Integer
       biBitCount As Integer
       biCompression As Long
       biSizeImage As Long
       biXPel{*filter*}eter As Long
       biYPel{*filter*}eter As Long
       biClrUsed As Long
       biClrImportant As Long
End Type

Private Type RGBQUAD
       rgbBlue As Byte
       rgbGreen As Byte
       rgbRed As Byte
       rgbReserved As Byte
End Type

Private Type BitMapInfo
       bmiHeader As BITMAPINFOHEADER
       bmiColors(1 To 256) As RGBQUAD
End Type

Private Type BITMAP '14 bytes
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
End Type

Private Declare Function CreateCompatibleDC Lib "GDI32" _
  (ByVal hdc As Long) As Long

Private Declare Function GetDIBits Lib "GDI32" (ByVal aHDC As Long, _
  ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long,
_
  ByVal lpBits As Long, lpBI As BitMapInfo, ByVal wUsage As Long) As Long

Private Declare Function SelectObject Lib "GDI32" (ByVal hdc As Long, _
         ByVal hObject As Long) As Long

Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" _
  (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, _
  ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long

Private Declare Function GetObject Lib "GDI32" Alias "GetObjectA" _
  (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) _
  As Long

Private Sub Command1_Click()
   Dim hBmp As Long
   Dim msg As String

    hBmp = LoadImage(0, "c:\Temp\stone.bmp", IMAGE_BITMAP, 0, 0, _
                    LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
    msg = "hBmp:" & hBmp & vbCrLf

    ' create dc
    Dim hdc As Long
    hdc = CreateCompatibleDC(0)
    msg = msg & "hDC:" & hdc & vbCrLf

    ' select bmp into dc
    Dim hBmp0
    hBmp0 = SelectObject(hdc, hBmp)

    ' get some bitmap information
    Dim bmp As BITMAP
    GetObject hBmp, Len(bmp), bmp
    msg = msg & bmp.bmWidth & "x" & bmp.bmHeight & " Pixel: " &
bmp.bmBitsPixel _
    & " Bytes: " & bmp.bmWidthBytes & vbCrLf

    Dim bi As BitMapInfo
    bi.bmiHeader.biSize = Len(bi.bmiHeader)       'Len(bi)
    msg = msg & "GetDIBits: " & GetDIBits(hdc, hBmp, 0, 0, 0, bi, 0) &
vbCrLf
    msg = msg & "Last Error: " & Err.LastDllError & vbCrLf
    msg = msg & bi.bmiHeader.biHeight & "x" & bi.bmiHeader.biWidth & _
    " Count: " & bi.bmiHeader.biBitCount & " Size: " &
bi.bmiHeader.biSizeImage
    MsgBox msg

End Sub
'===============================================================

Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.              



Fri, 11 Feb 2005 21:38:46 GMT  
 GetDIBits works on Win2K not Win98?

Cool, thanks. That did work! it made me check my declares. My GetDIBits
lpBits was declared "as any" , you used "as long". I made the change and it
seems to have been the problem. Thanks again!



Quote:
> Hi DB,

> Here is the code sample with all Declares. I tested it out on Win98 and it
> worked fine. Can you check this out:

> '==========================================================
> Const IMAGE_BITMAP = &O0
> Const LR_LOADFROMFILE = &H10
> Const LR_DEFAULTSIZE = &H40
> Const LR_CREATEDIBSECTION = &H2000

> Private Type BITMAPINFOHEADER
>        biSize As Long
>        biWidth As Long
>        biHeight As Long
>        biPlanes As Integer
>        biBitCount As Integer
>        biCompression As Long
>        biSizeImage As Long
>        biXPel{*filter*}eter As Long
>        biYPel{*filter*}eter As Long
>        biClrUsed As Long
>        biClrImportant As Long
> End Type

> Private Type RGBQUAD
>        rgbBlue As Byte
>        rgbGreen As Byte
>        rgbRed As Byte
>        rgbReserved As Byte
> End Type

> Private Type BitMapInfo
>        bmiHeader As BITMAPINFOHEADER
>        bmiColors(1 To 256) As RGBQUAD
> End Type

> Private Type BITMAP '14 bytes
>     bmType As Long
>     bmWidth As Long
>     bmHeight As Long
>     bmWidthBytes As Long
>     bmPlanes As Integer
>     bmBitsPixel As Integer
>     bmBits As Long
> End Type

> Private Declare Function CreateCompatibleDC Lib "GDI32" _
>   (ByVal hdc As Long) As Long

> Private Declare Function GetDIBits Lib "GDI32" (ByVal aHDC As Long, _
>   ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As
Long,
> _
>   ByVal lpBits As Long, lpBI As BitMapInfo, ByVal wUsage As Long) As Long

> Private Declare Function SelectObject Lib "GDI32" (ByVal hdc As Long, _
>          ByVal hObject As Long) As Long

> Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" _
>   (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, _
>   ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long

> Private Declare Function GetObject Lib "GDI32" Alias "GetObjectA" _
>   (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) _
>   As Long

> Private Sub Command1_Click()
>    Dim hBmp As Long
>    Dim msg As String

>     hBmp = LoadImage(0, "c:\Temp\stone.bmp", IMAGE_BITMAP, 0, 0, _
>                     LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
>     msg = "hBmp:" & hBmp & vbCrLf

>     ' create dc
>     Dim hdc As Long
>     hdc = CreateCompatibleDC(0)
>     msg = msg & "hDC:" & hdc & vbCrLf

>     ' select bmp into dc
>     Dim hBmp0
>     hBmp0 = SelectObject(hdc, hBmp)

>     ' get some bitmap information
>     Dim bmp As BITMAP
>     GetObject hBmp, Len(bmp), bmp
>     msg = msg & bmp.bmWidth & "x" & bmp.bmHeight & " Pixel: " &
> bmp.bmBitsPixel _
>     & " Bytes: " & bmp.bmWidthBytes & vbCrLf

>     Dim bi As BitMapInfo
>     bi.bmiHeader.biSize = Len(bi.bmiHeader)       'Len(bi)
>     msg = msg & "GetDIBits: " & GetDIBits(hdc, hBmp, 0, 0, 0, bi, 0) &
> vbCrLf
>     msg = msg & "Last Error: " & Err.LastDllError & vbCrLf
>     msg = msg & bi.bmiHeader.biHeight & "x" & bi.bmiHeader.biWidth & _
>     " Count: " & bi.bmiHeader.biBitCount & " Size: " &
> bi.bmiHeader.biSizeImage
>     MsgBox msg

> End Sub
> '===============================================================

> Hope this helps!
> Bharat Patel
> Microsoft, Visual Basic .NET

> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Please reply to newsgroups only. Thanks.



Fri, 11 Feb 2005 22:51:02 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Database works in Win98 but not Win2K

2. Access XP - Reports run under Win2K, not under Win98

3. Program runs on Win98 but not on Win2K

4. RegOpenKeyEx, Not Working on Win95 (but working on win98 and NT)

5. Huge GetDIBits slowdown under Win2K/XP

6. CDONTS.Newmail not working in Win2K

7. script works under 98, not under win2k

8. Webclasses Win2k ADO Connection not working - urgent help needed

9. CommonDialog Printer Setup not working properly in Win2K

10. Outlook Automation Works Under Win95 But Not Win2k

11. Outlook Automation Works in Win95 but not Win2k

12. CDONTS.Newmail not working in Win2K

 

 
Powered by phpBB® Forum Software