Win32 API 日本語リファレンス
ホームGraphics.Gdi › GetBitmapBits

GetBitmapBits

関数
ビットマップのビット列をバッファへコピーする。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// GDI32.dll
#include <windows.h>

INT GetBitmapBits(
    HBITMAP hbit,
    INT cb,
    void* lpvBits
);

パラメーター

名前方向
hbitHBITMAPin
cbINTin
lpvBitsvoid*out

戻り値の型: INT

各言語での呼び出し定義

// GDI32.dll
#include <windows.h>

INT GetBitmapBits(
    HBITMAP hbit,
    INT cb,
    void* lpvBits
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern int GetBitmapBits(
    IntPtr hbit,   // HBITMAP
    int cb,   // INT
    IntPtr lpvBits   // void* out
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function GetBitmapBits(
    hbit As IntPtr,   ' HBITMAP
    cb As Integer,   ' INT
    lpvBits As IntPtr   ' void* out
) As Integer
End Function
' hbit : HBITMAP
' cb : INT
' lpvBits : void* out
Declare PtrSafe Function GetBitmapBits Lib "gdi32" ( _
    ByVal hbit As LongPtr, _
    ByVal cb As Long, _
    ByVal lpvBits As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetBitmapBits = ctypes.windll.gdi32.GetBitmapBits
GetBitmapBits.restype = ctypes.c_int
GetBitmapBits.argtypes = [
    wintypes.HANDLE,  # hbit : HBITMAP
    ctypes.c_int,  # cb : INT
    ctypes.POINTER(None),  # lpvBits : void* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
GetBitmapBits = Fiddle::Function.new(
  lib['GetBitmapBits'],
  [
    Fiddle::TYPE_VOIDP,  # hbit : HBITMAP
    Fiddle::TYPE_INT,  # cb : INT
    Fiddle::TYPE_VOIDP,  # lpvBits : void* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn GetBitmapBits(
        hbit: *mut core::ffi::c_void,  // HBITMAP
        cb: i32,  // INT
        lpvBits: *mut ()  // void* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll")]
public static extern int GetBitmapBits(IntPtr hbit, int cb, IntPtr lpvBits);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetBitmapBits' -Namespace Win32 -PassThru
# $api::GetBitmapBits(hbit, cb, lpvBits)
#uselib "GDI32.dll"
#func global GetBitmapBits "GetBitmapBits" sptr, sptr, sptr
; GetBitmapBits hbit, cb, lpvBits   ; 戻り値は stat
; hbit : HBITMAP -> "sptr"
; cb : INT -> "sptr"
; lpvBits : void* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global GetBitmapBits "GetBitmapBits" sptr, int, sptr
; res = GetBitmapBits(hbit, cb, lpvBits)
; hbit : HBITMAP -> "sptr"
; cb : INT -> "int"
; lpvBits : void* out -> "sptr"
; INT GetBitmapBits(HBITMAP hbit, INT cb, void* lpvBits)
#uselib "GDI32.dll"
#cfunc global GetBitmapBits "GetBitmapBits" intptr, int, intptr
; res = GetBitmapBits(hbit, cb, lpvBits)
; hbit : HBITMAP -> "intptr"
; cb : INT -> "int"
; lpvBits : void* out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetBitmapBits = gdi32.NewProc("GetBitmapBits")
)

// hbit (HBITMAP), cb (INT), lpvBits (void* out)
r1, _, err := procGetBitmapBits.Call(
	uintptr(hbit),
	uintptr(cb),
	uintptr(lpvBits),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function GetBitmapBits(
  hbit: THandle;   // HBITMAP
  cb: Integer;   // INT
  lpvBits: Pointer   // void* out
): Integer; stdcall;
  external 'GDI32.dll' name 'GetBitmapBits';
result := DllCall("GDI32\GetBitmapBits"
    , "Ptr", hbit   ; HBITMAP
    , "Int", cb   ; INT
    , "Ptr", lpvBits   ; void* out
    , "Int")   ; return: INT
●GetBitmapBits(hbit, cb, lpvBits) = DLL("GDI32.dll", "int GetBitmapBits(void*, int, void*)")
# 呼び出し: GetBitmapBits(hbit, cb, lpvBits)
# hbit : HBITMAP -> "void*"
# cb : INT -> "int"
# lpvBits : void* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。