[VBA] GDI32 GetObjectA 沒有值0

  • 90
  • 0
  • VBA
  • 2022-05-28

GDI32 GetObjectA  沒有值0

[VBA]學習讀取BMP點陣圖資訊

Type Bitmap
       bmType As Long
       bmWidth As Long
       bmHeight As Long
       bmWidthBytes As Long
       bmPlanes As Integer
       bmBitsPixel As Integer
       bmBits As Long
       'exByate(200) As Byte
End Type

Private Declare PtrSafe Function GetObject32 Lib "gdi32" Alias "GetObjectA" _
       (ByVal hObject As LongPtr, ByVal nCount As LongLong, lpObject As Any) _
       As Long
Private Sub readBmpInfo()
	Dim hBitmap As IPictureDisp
	Dim res As Long
	Dim bmp As sBitmap
	Set hBitmap = LoadPicture("web.bmp")
	res = GetObject32(hBitmap, Len(bmp), bmp)   '取得BitMap的結構
End Sub

GetObjectA參數lpObject 的結構大小要大於hObject丟進來的資料

Bitmap大小只有24Bytes 可是資料有32Bytes所以GetObject32 最後沒反應只有回饋0

最後Bitmap最後塞個Bytes(200) <ps.只要比資料大就好了>就執行成功

不管結構容器多大res只會反饋資料大小32

參考

https://docs.microsoft.com/zh-tw/windows/win32/api/wingdi/ns-wingdi-bitmap

https://www.hosp.ncku.edu.tw/~cww/html/q00119.html