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

SetDIBitsToDevice

関数
DIBのピクセルを直接デバイスの矩形領域へ転送する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

INT SetDIBitsToDevice(
    HDC hdc,
    INT xDest,
    INT yDest,
    DWORD w,
    DWORD h,
    INT xSrc,
    INT ySrc,
    DWORD StartScan,
    DWORD cLines,
    const void* lpvBits,
    const BITMAPINFO* lpbmi,
    DIB_USAGE ColorUse
);

パラメーター

名前方向説明
hdcHDCinデバイスコンテキストへのハンドル。
xDestINTinデスティネーション矩形の左上隅の x 座標(論理単位)。
yDestINTinデスティネーション矩形の左上隅の y 座標(論理単位)。
wDWORDin画像の幅(論理単位)。
hDWORDin画像の高さ(論理単位)。
xSrcINTin画像の左下隅の x 座標(論理単位)。
ySrcINTin画像の左下隅の y 座標(論理単位)。
StartScanDWORDin画像内の開始スキャンライン。
cLinesDWORDinlpvBits パラメーターが指す配列に含まれる DIB スキャンラインの数。
lpvBitsvoid*inバイト配列として格納された色データへのポインター。詳細については、次の「解説」セクションを参照してください。
lpbmiBITMAPINFO*inDIB に関する情報を含む BITMAPINFO 構造体へのポインター。
ColorUseDIB_USAGEin

BITMAPINFO 構造体の bmiColors メンバーに、明示的な赤、緑、青(RGB)の値が含まれているか、パレットへのインデックスが含まれているかを示します。詳細については、次の「解説」セクションを参照してください。

fuColorUse パラメーターは、次のいずれかの値である必要があります。

意味
DIB_PAL_COLORS
カラーテーブルは、現在選択されている論理パレットへの 16 ビットインデックスの配列で構成されます。
DIB_RGB_COLORS
カラーテーブルにはリテラルの RGB 値が含まれます。

戻り値の型: INT

公式ドキュメント

SetDIBitsToDevice 関数は、DIB、JPEG、または PNG 画像の色データを使用して、デスティネーションデバイスコンテキストに関連付けられたデバイス上の指定された矩形内のピクセルを設定します。

戻り値

関数が成功した場合、戻り値は設定されたスキャンラインの数です。

設定されたスキャンラインがゼロの場合(dwHeight が 0 のときなど)、または関数が失敗した場合、関数はゼロを返します。

ドライバーが SetDIBitsToDevice に渡された JPEG または PNG ファイル画像をサポートできない場合、関数は失敗し GDI_ERROR を返します。失敗が発生した場合、アプリケーションは独自の JPEG または PNG サポートにフォールバックして画像をビットマップに展開し、そのビットマップを SetDIBitsToDevice に渡す必要があります。

解説(Remarks)

最適なビットマップ描画速度は、ビットマップのビットがシステムパレットへのインデックスである場合に得られます。

アプリケーションは、GetSystemPaletteEntries 関数を呼び出すことで、システムパレットの色とインデックスを取得できます。色とインデックスを取得した後、アプリケーションは DIB を作成できます。システムパレットの詳細については、Colors を参照してください。

スキャンラインは、RLE 圧縮ビットマップを除き、DWORD 境界に整列している必要があります。

ボトムアップ DIB の原点はビットマップの左下隅であり、トップダウン DIB の原点は左上隅です。

大きな DIB からデバイスサーフェスにビットを設定するために必要なメモリ量を削減するために、アプリケーションは SetDIBitsToDevice を繰り返し呼び出し、毎回ビットマップの異なる部分を lpvBits 配列に配置することで、出力をバンド処理できます。uStartScan および cScanLines パラメーターの値は、lpvBits 配列に含まれるビットマップの部分を識別します。

SetDIBitsToDevice 関数は、フルスクリーンの MS-DOS セッションがフォアグラウンドで実行されている間にバックグラウンドで実行されているプロセスから呼び出された場合、エラーを返します。

ICM: SetICMModeiEnableICM パラメーターを ICM_ON に設定して呼び出すことでカラーマネジメントが有効になっている場合、カラーマネジメントが実行されます。lpbmi で指定されたビットマップが、gamma および endpoints メンバーを指定する BITMAPV4HEADER、または gamma および endpoints メンバーか profileData および profileSize メンバーのいずれかを指定する BITMAPV5HEADER を持つ場合、この呼び出しはビットマップのピクセルを、デバイスコンテキストのソース色空間ではなく、それらのメンバーによって記述された色空間で表現されているものとして扱います。

例については、Testing a Printer for JPEG or PNG Support を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

INT SetDIBitsToDevice(
    HDC hdc,
    INT xDest,
    INT yDest,
    DWORD w,
    DWORD h,
    INT xSrc,
    INT ySrc,
    DWORD StartScan,
    DWORD cLines,
    const void* lpvBits,
    const BITMAPINFO* lpbmi,
    DIB_USAGE ColorUse
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern int SetDIBitsToDevice(
    IntPtr hdc,   // HDC
    int xDest,   // INT
    int yDest,   // INT
    uint w,   // DWORD
    uint h,   // DWORD
    int xSrc,   // INT
    int ySrc,   // INT
    uint StartScan,   // DWORD
    uint cLines,   // DWORD
    IntPtr lpvBits,   // void*
    IntPtr lpbmi,   // BITMAPINFO*
    uint ColorUse   // DIB_USAGE
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function SetDIBitsToDevice(
    hdc As IntPtr,   ' HDC
    xDest As Integer,   ' INT
    yDest As Integer,   ' INT
    w As UInteger,   ' DWORD
    h As UInteger,   ' DWORD
    xSrc As Integer,   ' INT
    ySrc As Integer,   ' INT
    StartScan As UInteger,   ' DWORD
    cLines As UInteger,   ' DWORD
    lpvBits As IntPtr,   ' void*
    lpbmi As IntPtr,   ' BITMAPINFO*
    ColorUse As UInteger   ' DIB_USAGE
) As Integer
End Function
' hdc : HDC
' xDest : INT
' yDest : INT
' w : DWORD
' h : DWORD
' xSrc : INT
' ySrc : INT
' StartScan : DWORD
' cLines : DWORD
' lpvBits : void*
' lpbmi : BITMAPINFO*
' ColorUse : DIB_USAGE
Declare PtrSafe Function SetDIBitsToDevice Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal xDest As Long, _
    ByVal yDest As Long, _
    ByVal w As Long, _
    ByVal h As Long, _
    ByVal xSrc As Long, _
    ByVal ySrc As Long, _
    ByVal StartScan As Long, _
    ByVal cLines As Long, _
    ByVal lpvBits As LongPtr, _
    ByVal lpbmi As LongPtr, _
    ByVal ColorUse As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetDIBitsToDevice = ctypes.windll.gdi32.SetDIBitsToDevice
SetDIBitsToDevice.restype = ctypes.c_int
SetDIBitsToDevice.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # xDest : INT
    ctypes.c_int,  # yDest : INT
    wintypes.DWORD,  # w : DWORD
    wintypes.DWORD,  # h : DWORD
    ctypes.c_int,  # xSrc : INT
    ctypes.c_int,  # ySrc : INT
    wintypes.DWORD,  # StartScan : DWORD
    wintypes.DWORD,  # cLines : DWORD
    ctypes.POINTER(None),  # lpvBits : void*
    ctypes.c_void_p,  # lpbmi : BITMAPINFO*
    wintypes.DWORD,  # ColorUse : DIB_USAGE
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
SetDIBitsToDevice = Fiddle::Function.new(
  lib['SetDIBitsToDevice'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_INT,  # xDest : INT
    Fiddle::TYPE_INT,  # yDest : INT
    -Fiddle::TYPE_INT,  # w : DWORD
    -Fiddle::TYPE_INT,  # h : DWORD
    Fiddle::TYPE_INT,  # xSrc : INT
    Fiddle::TYPE_INT,  # ySrc : INT
    -Fiddle::TYPE_INT,  # StartScan : DWORD
    -Fiddle::TYPE_INT,  # cLines : DWORD
    Fiddle::TYPE_VOIDP,  # lpvBits : void*
    Fiddle::TYPE_VOIDP,  # lpbmi : BITMAPINFO*
    -Fiddle::TYPE_INT,  # ColorUse : DIB_USAGE
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn SetDIBitsToDevice(
        hdc: *mut core::ffi::c_void,  // HDC
        xDest: i32,  // INT
        yDest: i32,  // INT
        w: u32,  // DWORD
        h: u32,  // DWORD
        xSrc: i32,  // INT
        ySrc: i32,  // INT
        StartScan: u32,  // DWORD
        cLines: u32,  // DWORD
        lpvBits: *const (),  // void*
        lpbmi: *const BITMAPINFO,  // BITMAPINFO*
        ColorUse: u32  // DIB_USAGE
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll")]
public static extern int SetDIBitsToDevice(IntPtr hdc, int xDest, int yDest, uint w, uint h, int xSrc, int ySrc, uint StartScan, uint cLines, IntPtr lpvBits, IntPtr lpbmi, uint ColorUse);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_SetDIBitsToDevice' -Namespace Win32 -PassThru
# $api::SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
#uselib "GDI32.dll"
#func global SetDIBitsToDevice "SetDIBitsToDevice" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetDIBitsToDevice hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, varptr(lpbmi), ColorUse   ; 戻り値は stat
; hdc : HDC -> "sptr"
; xDest : INT -> "sptr"
; yDest : INT -> "sptr"
; w : DWORD -> "sptr"
; h : DWORD -> "sptr"
; xSrc : INT -> "sptr"
; ySrc : INT -> "sptr"
; StartScan : DWORD -> "sptr"
; cLines : DWORD -> "sptr"
; lpvBits : void* -> "sptr"
; lpbmi : BITMAPINFO* -> "sptr"
; ColorUse : DIB_USAGE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global SetDIBitsToDevice "SetDIBitsToDevice" sptr, int, int, int, int, int, int, int, int, sptr, var, int
; res = SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
; hdc : HDC -> "sptr"
; xDest : INT -> "int"
; yDest : INT -> "int"
; w : DWORD -> "int"
; h : DWORD -> "int"
; xSrc : INT -> "int"
; ySrc : INT -> "int"
; StartScan : DWORD -> "int"
; cLines : DWORD -> "int"
; lpvBits : void* -> "sptr"
; lpbmi : BITMAPINFO* -> "var"
; ColorUse : DIB_USAGE -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT SetDIBitsToDevice(HDC hdc, INT xDest, INT yDest, DWORD w, DWORD h, INT xSrc, INT ySrc, DWORD StartScan, DWORD cLines, void* lpvBits, BITMAPINFO* lpbmi, DIB_USAGE ColorUse)
#uselib "GDI32.dll"
#cfunc global SetDIBitsToDevice "SetDIBitsToDevice" intptr, int, int, int, int, int, int, int, int, intptr, var, int
; res = SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
; hdc : HDC -> "intptr"
; xDest : INT -> "int"
; yDest : INT -> "int"
; w : DWORD -> "int"
; h : DWORD -> "int"
; xSrc : INT -> "int"
; ySrc : INT -> "int"
; StartScan : DWORD -> "int"
; cLines : DWORD -> "int"
; lpvBits : void* -> "intptr"
; lpbmi : BITMAPINFO* -> "var"
; ColorUse : DIB_USAGE -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procSetDIBitsToDevice = gdi32.NewProc("SetDIBitsToDevice")
)

// hdc (HDC), xDest (INT), yDest (INT), w (DWORD), h (DWORD), xSrc (INT), ySrc (INT), StartScan (DWORD), cLines (DWORD), lpvBits (void*), lpbmi (BITMAPINFO*), ColorUse (DIB_USAGE)
r1, _, err := procSetDIBitsToDevice.Call(
	uintptr(hdc),
	uintptr(xDest),
	uintptr(yDest),
	uintptr(w),
	uintptr(h),
	uintptr(xSrc),
	uintptr(ySrc),
	uintptr(StartScan),
	uintptr(cLines),
	uintptr(lpvBits),
	uintptr(lpbmi),
	uintptr(ColorUse),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function SetDIBitsToDevice(
  hdc: THandle;   // HDC
  xDest: Integer;   // INT
  yDest: Integer;   // INT
  w: DWORD;   // DWORD
  h: DWORD;   // DWORD
  xSrc: Integer;   // INT
  ySrc: Integer;   // INT
  StartScan: DWORD;   // DWORD
  cLines: DWORD;   // DWORD
  lpvBits: Pointer;   // void*
  lpbmi: Pointer;   // BITMAPINFO*
  ColorUse: DWORD   // DIB_USAGE
): Integer; stdcall;
  external 'GDI32.dll' name 'SetDIBitsToDevice';
result := DllCall("GDI32\SetDIBitsToDevice"
    , "Ptr", hdc   ; HDC
    , "Int", xDest   ; INT
    , "Int", yDest   ; INT
    , "UInt", w   ; DWORD
    , "UInt", h   ; DWORD
    , "Int", xSrc   ; INT
    , "Int", ySrc   ; INT
    , "UInt", StartScan   ; DWORD
    , "UInt", cLines   ; DWORD
    , "Ptr", lpvBits   ; void*
    , "Ptr", lpbmi   ; BITMAPINFO*
    , "UInt", ColorUse   ; DIB_USAGE
    , "Int")   ; return: INT
●SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse) = DLL("GDI32.dll", "int SetDIBitsToDevice(void*, int, int, dword, dword, int, int, dword, dword, void*, void*, dword)")
# 呼び出し: SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
# hdc : HDC -> "void*"
# xDest : INT -> "int"
# yDest : INT -> "int"
# w : DWORD -> "dword"
# h : DWORD -> "dword"
# xSrc : INT -> "int"
# ySrc : INT -> "int"
# StartScan : DWORD -> "dword"
# cLines : DWORD -> "dword"
# lpvBits : void* -> "void*"
# lpbmi : BITMAPINFO* -> "void*"
# ColorUse : DIB_USAGE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "gdi32" fn SetDIBitsToDevice(
    hdc: ?*anyopaque, // HDC
    xDest: i32, // INT
    yDest: i32, // INT
    w: u32, // DWORD
    h: u32, // DWORD
    xSrc: i32, // INT
    ySrc: i32, // INT
    StartScan: u32, // DWORD
    cLines: u32, // DWORD
    lpvBits: ?*anyopaque, // void*
    lpbmi: [*c]BITMAPINFO, // BITMAPINFO*
    ColorUse: u32 // DIB_USAGE
) callconv(std.os.windows.WINAPI) i32;
proc SetDIBitsToDevice(
    hdc: pointer,  # HDC
    xDest: int32,  # INT
    yDest: int32,  # INT
    w: uint32,  # DWORD
    h: uint32,  # DWORD
    xSrc: int32,  # INT
    ySrc: int32,  # INT
    StartScan: uint32,  # DWORD
    cLines: uint32,  # DWORD
    lpvBits: pointer,  # void*
    lpbmi: ptr BITMAPINFO,  # BITMAPINFO*
    ColorUse: uint32  # DIB_USAGE
): int32 {.importc: "SetDIBitsToDevice", stdcall, dynlib: "GDI32.dll".}
pragma(lib, "gdi32");
extern(Windows)
int SetDIBitsToDevice(
    void* hdc,   // HDC
    int xDest,   // INT
    int yDest,   // INT
    uint w,   // DWORD
    uint h,   // DWORD
    int xSrc,   // INT
    int ySrc,   // INT
    uint StartScan,   // DWORD
    uint cLines,   // DWORD
    void* lpvBits,   // void*
    BITMAPINFO* lpbmi,   // BITMAPINFO*
    uint ColorUse   // DIB_USAGE
);
ccall((:SetDIBitsToDevice, "GDI32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Int32, UInt32, UInt32, Int32, Int32, UInt32, UInt32, Ptr{Cvoid}, Ptr{BITMAPINFO}, UInt32),
      hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
# hdc : HDC -> Ptr{Cvoid}
# xDest : INT -> Int32
# yDest : INT -> Int32
# w : DWORD -> UInt32
# h : DWORD -> UInt32
# xSrc : INT -> Int32
# ySrc : INT -> Int32
# StartScan : DWORD -> UInt32
# cLines : DWORD -> UInt32
# lpvBits : void* -> Ptr{Cvoid}
# lpbmi : BITMAPINFO* -> Ptr{BITMAPINFO}
# ColorUse : DIB_USAGE -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetDIBitsToDevice(
    void* hdc,
    int32_t xDest,
    int32_t yDest,
    uint32_t w,
    uint32_t h,
    int32_t xSrc,
    int32_t ySrc,
    uint32_t StartScan,
    uint32_t cLines,
    void* lpvBits,
    void* lpbmi,
    uint32_t ColorUse);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
-- hdc : HDC
-- xDest : INT
-- yDest : INT
-- w : DWORD
-- h : DWORD
-- xSrc : INT
-- ySrc : INT
-- StartScan : DWORD
-- cLines : DWORD
-- lpvBits : void*
-- lpbmi : BITMAPINFO*
-- ColorUse : DIB_USAGE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const SetDIBitsToDevice = lib.func('__stdcall', 'SetDIBitsToDevice', 'int32_t', ['void *', 'int32_t', 'int32_t', 'uint32_t', 'uint32_t', 'int32_t', 'int32_t', 'uint32_t', 'uint32_t', 'void *', 'void *', 'uint32_t']);
// SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
// hdc : HDC -> 'void *'
// xDest : INT -> 'int32_t'
// yDest : INT -> 'int32_t'
// w : DWORD -> 'uint32_t'
// h : DWORD -> 'uint32_t'
// xSrc : INT -> 'int32_t'
// ySrc : INT -> 'int32_t'
// StartScan : DWORD -> 'uint32_t'
// cLines : DWORD -> 'uint32_t'
// lpvBits : void* -> 'void *'
// lpbmi : BITMAPINFO* -> 'void *'
// ColorUse : DIB_USAGE -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("GDI32.dll", {
  SetDIBitsToDevice: { parameters: ["pointer", "i32", "i32", "u32", "u32", "i32", "i32", "u32", "u32", "pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
// hdc : HDC -> "pointer"
// xDest : INT -> "i32"
// yDest : INT -> "i32"
// w : DWORD -> "u32"
// h : DWORD -> "u32"
// xSrc : INT -> "i32"
// ySrc : INT -> "i32"
// StartScan : DWORD -> "u32"
// cLines : DWORD -> "u32"
// lpvBits : void* -> "pointer"
// lpbmi : BITMAPINFO* -> "pointer"
// ColorUse : DIB_USAGE -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetDIBitsToDevice(
    void* hdc,
    int32_t xDest,
    int32_t yDest,
    uint32_t w,
    uint32_t h,
    int32_t xSrc,
    int32_t ySrc,
    uint32_t StartScan,
    uint32_t cLines,
    void* lpvBits,
    void* lpbmi,
    uint32_t ColorUse);
C, "GDI32.dll");
// $ffi->SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse);
// hdc : HDC
// xDest : INT
// yDest : INT
// w : DWORD
// h : DWORD
// xSrc : INT
// ySrc : INT
// StartScan : DWORD
// cLines : DWORD
// lpvBits : void*
// lpbmi : BITMAPINFO*
// ColorUse : DIB_USAGE
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Gdi32 extends StdCallLibrary {
    Gdi32 INSTANCE = Native.load("gdi32", Gdi32.class);
    int SetDIBitsToDevice(
        Pointer hdc,   // HDC
        int xDest,   // INT
        int yDest,   // INT
        int w,   // DWORD
        int h,   // DWORD
        int xSrc,   // INT
        int ySrc,   // INT
        int StartScan,   // DWORD
        int cLines,   // DWORD
        Pointer lpvBits,   // void*
        Pointer lpbmi,   // BITMAPINFO*
        int ColorUse   // DIB_USAGE
    );
}
@[Link("gdi32")]
lib LibGDI32
  fun SetDIBitsToDevice = SetDIBitsToDevice(
    hdc : Void*,   # HDC
    xDest : Int32,   # INT
    yDest : Int32,   # INT
    w : UInt32,   # DWORD
    h : UInt32,   # DWORD
    xSrc : Int32,   # INT
    ySrc : Int32,   # INT
    StartScan : UInt32,   # DWORD
    cLines : UInt32,   # DWORD
    lpvBits : Void*,   # void*
    lpbmi : BITMAPINFO*,   # BITMAPINFO*
    ColorUse : UInt32   # DIB_USAGE
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetDIBitsToDeviceNative = Int32 Function(Pointer<Void>, Int32, Int32, Uint32, Uint32, Int32, Int32, Uint32, Uint32, Pointer<Void>, Pointer<Void>, Uint32);
typedef SetDIBitsToDeviceDart = int Function(Pointer<Void>, int, int, int, int, int, int, int, int, Pointer<Void>, Pointer<Void>, int);
final SetDIBitsToDevice = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<SetDIBitsToDeviceNative, SetDIBitsToDeviceDart>('SetDIBitsToDevice');
// hdc : HDC -> Pointer<Void>
// xDest : INT -> Int32
// yDest : INT -> Int32
// w : DWORD -> Uint32
// h : DWORD -> Uint32
// xSrc : INT -> Int32
// ySrc : INT -> Int32
// StartScan : DWORD -> Uint32
// cLines : DWORD -> Uint32
// lpvBits : void* -> Pointer<Void>
// lpbmi : BITMAPINFO* -> Pointer<Void>
// ColorUse : DIB_USAGE -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetDIBitsToDevice(
  hdc: THandle;   // HDC
  xDest: Integer;   // INT
  yDest: Integer;   // INT
  w: DWORD;   // DWORD
  h: DWORD;   // DWORD
  xSrc: Integer;   // INT
  ySrc: Integer;   // INT
  StartScan: DWORD;   // DWORD
  cLines: DWORD;   // DWORD
  lpvBits: Pointer;   // void*
  lpbmi: Pointer;   // BITMAPINFO*
  ColorUse: DWORD   // DIB_USAGE
): Integer; stdcall;
  external 'GDI32.dll' name 'SetDIBitsToDevice';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetDIBitsToDevice"
  c_SetDIBitsToDevice :: Ptr () -> Int32 -> Int32 -> Word32 -> Word32 -> Int32 -> Int32 -> Word32 -> Word32 -> Ptr () -> Ptr () -> Word32 -> IO Int32
-- hdc : HDC -> Ptr ()
-- xDest : INT -> Int32
-- yDest : INT -> Int32
-- w : DWORD -> Word32
-- h : DWORD -> Word32
-- xSrc : INT -> Int32
-- ySrc : INT -> Int32
-- StartScan : DWORD -> Word32
-- cLines : DWORD -> Word32
-- lpvBits : void* -> Ptr ()
-- lpbmi : BITMAPINFO* -> Ptr ()
-- ColorUse : DIB_USAGE -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setdibitstodevice =
  foreign "SetDIBitsToDevice"
    ((ptr void) @-> int32_t @-> int32_t @-> uint32_t @-> uint32_t @-> int32_t @-> int32_t @-> uint32_t @-> uint32_t @-> (ptr void) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* xDest : INT -> int32_t *)
(* yDest : INT -> int32_t *)
(* w : DWORD -> uint32_t *)
(* h : DWORD -> uint32_t *)
(* xSrc : INT -> int32_t *)
(* ySrc : INT -> int32_t *)
(* StartScan : DWORD -> uint32_t *)
(* cLines : DWORD -> uint32_t *)
(* lpvBits : void* -> (ptr void) *)
(* lpbmi : BITMAPINFO* -> (ptr void) *)
(* ColorUse : DIB_USAGE -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("SetDIBitsToDevice" set-dibits-to-device :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (x-dest :int32)   ; INT
  (y-dest :int32)   ; INT
  (w :uint32)   ; DWORD
  (h :uint32)   ; DWORD
  (x-src :int32)   ; INT
  (y-src :int32)   ; INT
  (start-scan :uint32)   ; DWORD
  (c-lines :uint32)   ; DWORD
  (lpv-bits :pointer)   ; void*
  (lpbmi :pointer)   ; BITMAPINFO*
  (color-use :uint32))   ; DIB_USAGE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetDIBitsToDevice = Win32::API::More->new('GDI32',
    'int SetDIBitsToDevice(HANDLE hdc, int xDest, int yDest, DWORD w, DWORD h, int xSrc, int ySrc, DWORD StartScan, DWORD cLines, LPVOID lpvBits, LPVOID lpbmi, DWORD ColorUse)');
# my $ret = $SetDIBitsToDevice->Call($hdc, $xDest, $yDest, $w, $h, $xSrc, $ySrc, $StartScan, $cLines, $lpvBits, $lpbmi, $ColorUse);
# hdc : HDC -> HANDLE
# xDest : INT -> int
# yDest : INT -> int
# w : DWORD -> DWORD
# h : DWORD -> DWORD
# xSrc : INT -> int
# ySrc : INT -> int
# StartScan : DWORD -> DWORD
# cLines : DWORD -> DWORD
# lpvBits : void* -> LPVOID
# lpbmi : BITMAPINFO* -> LPVOID
# ColorUse : DIB_USAGE -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型