ホーム › Graphics.Gdi › CreateDIBSection
CreateDIBSection
関数アプリが直接アクセス可能なメモリを持つDIBセクションを作成する。
シグネチャ
// GDI32.dll
#include <windows.h>
HBITMAP CreateDIBSection(
HDC hdc, // optional
const BITMAPINFO* pbmi,
DIB_USAGE usage,
void** ppvBits,
HANDLE hSection, // optional
DWORD offset
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hdc | HDC | inoptional |
| pbmi | BITMAPINFO* | in |
| usage | DIB_USAGE | in |
| ppvBits | void** | out |
| hSection | HANDLE | inoptional |
| offset | DWORD | in |
戻り値の型: HBITMAP
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
HBITMAP CreateDIBSection(
HDC hdc, // optional
const BITMAPINFO* pbmi,
DIB_USAGE usage,
void** ppvBits,
HANDLE hSection, // optional
DWORD offset
);[DllImport("GDI32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateDIBSection(
IntPtr hdc, // HDC optional
IntPtr pbmi, // BITMAPINFO*
uint usage, // DIB_USAGE
IntPtr ppvBits, // void** out
IntPtr hSection, // HANDLE optional
uint offset // DWORD
);<DllImport("GDI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateDIBSection(
hdc As IntPtr, ' HDC optional
pbmi As IntPtr, ' BITMAPINFO*
usage As UInteger, ' DIB_USAGE
ppvBits As IntPtr, ' void** out
hSection As IntPtr, ' HANDLE optional
offset As UInteger ' DWORD
) As IntPtr
End Function' hdc : HDC optional
' pbmi : BITMAPINFO*
' usage : DIB_USAGE
' ppvBits : void** out
' hSection : HANDLE optional
' offset : DWORD
Declare PtrSafe Function CreateDIBSection Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal pbmi As LongPtr, _
ByVal usage As Long, _
ByVal ppvBits As LongPtr, _
ByVal hSection As LongPtr, _
ByVal offset As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CreateDIBSection = ctypes.windll.gdi32.CreateDIBSection
CreateDIBSection.restype = ctypes.c_void_p
CreateDIBSection.argtypes = [
wintypes.HANDLE, # hdc : HDC optional
ctypes.c_void_p, # pbmi : BITMAPINFO*
wintypes.DWORD, # usage : DIB_USAGE
ctypes.c_void_p, # ppvBits : void** out
wintypes.HANDLE, # hSection : HANDLE optional
wintypes.DWORD, # offset : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
CreateDIBSection = Fiddle::Function.new(
lib['CreateDIBSection'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC optional
Fiddle::TYPE_VOIDP, # pbmi : BITMAPINFO*
-Fiddle::TYPE_INT, # usage : DIB_USAGE
Fiddle::TYPE_VOIDP, # ppvBits : void** out
Fiddle::TYPE_VOIDP, # hSection : HANDLE optional
-Fiddle::TYPE_INT, # offset : DWORD
],
Fiddle::TYPE_VOIDP)#[link(name = "gdi32")]
extern "system" {
fn CreateDIBSection(
hdc: *mut core::ffi::c_void, // HDC optional
pbmi: *const BITMAPINFO, // BITMAPINFO*
usage: u32, // DIB_USAGE
ppvBits: *mut *mut (), // void** out
hSection: *mut core::ffi::c_void, // HANDLE optional
offset: u32 // DWORD
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll", SetLastError = true)]
public static extern IntPtr CreateDIBSection(IntPtr hdc, IntPtr pbmi, uint usage, IntPtr ppvBits, IntPtr hSection, uint offset);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_CreateDIBSection' -Namespace Win32 -PassThru
# $api::CreateDIBSection(hdc, pbmi, usage, ppvBits, hSection, offset)#uselib "GDI32.dll"
#func global CreateDIBSection "CreateDIBSection" sptr, sptr, sptr, sptr, sptr, sptr
; CreateDIBSection hdc, varptr(pbmi), usage, ppvBits, hSection, offset ; 戻り値は stat
; hdc : HDC optional -> "sptr"
; pbmi : BITMAPINFO* -> "sptr"
; usage : DIB_USAGE -> "sptr"
; ppvBits : void** out -> "sptr"
; hSection : HANDLE optional -> "sptr"
; offset : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "GDI32.dll" #cfunc global CreateDIBSection "CreateDIBSection" sptr, var, int, sptr, sptr, int ; res = CreateDIBSection(hdc, pbmi, usage, ppvBits, hSection, offset) ; hdc : HDC optional -> "sptr" ; pbmi : BITMAPINFO* -> "var" ; usage : DIB_USAGE -> "int" ; ppvBits : void** out -> "sptr" ; hSection : HANDLE optional -> "sptr" ; offset : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "GDI32.dll" #cfunc global CreateDIBSection "CreateDIBSection" sptr, sptr, int, sptr, sptr, int ; res = CreateDIBSection(hdc, varptr(pbmi), usage, ppvBits, hSection, offset) ; hdc : HDC optional -> "sptr" ; pbmi : BITMAPINFO* -> "sptr" ; usage : DIB_USAGE -> "int" ; ppvBits : void** out -> "sptr" ; hSection : HANDLE optional -> "sptr" ; offset : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HBITMAP CreateDIBSection(HDC hdc, BITMAPINFO* pbmi, DIB_USAGE usage, void** ppvBits, HANDLE hSection, DWORD offset) #uselib "GDI32.dll" #cfunc global CreateDIBSection "CreateDIBSection" intptr, var, int, intptr, intptr, int ; res = CreateDIBSection(hdc, pbmi, usage, ppvBits, hSection, offset) ; hdc : HDC optional -> "intptr" ; pbmi : BITMAPINFO* -> "var" ; usage : DIB_USAGE -> "int" ; ppvBits : void** out -> "intptr" ; hSection : HANDLE optional -> "intptr" ; offset : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HBITMAP CreateDIBSection(HDC hdc, BITMAPINFO* pbmi, DIB_USAGE usage, void** ppvBits, HANDLE hSection, DWORD offset) #uselib "GDI32.dll" #cfunc global CreateDIBSection "CreateDIBSection" intptr, intptr, int, intptr, intptr, int ; res = CreateDIBSection(hdc, varptr(pbmi), usage, ppvBits, hSection, offset) ; hdc : HDC optional -> "intptr" ; pbmi : BITMAPINFO* -> "intptr" ; usage : DIB_USAGE -> "int" ; ppvBits : void** out -> "intptr" ; hSection : HANDLE optional -> "intptr" ; offset : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procCreateDIBSection = gdi32.NewProc("CreateDIBSection")
)
// hdc (HDC optional), pbmi (BITMAPINFO*), usage (DIB_USAGE), ppvBits (void** out), hSection (HANDLE optional), offset (DWORD)
r1, _, err := procCreateDIBSection.Call(
uintptr(hdc),
uintptr(pbmi),
uintptr(usage),
uintptr(ppvBits),
uintptr(hSection),
uintptr(offset),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HBITMAPfunction CreateDIBSection(
hdc: THandle; // HDC optional
pbmi: Pointer; // BITMAPINFO*
usage: DWORD; // DIB_USAGE
ppvBits: Pointer; // void** out
hSection: THandle; // HANDLE optional
offset: DWORD // DWORD
): THandle; stdcall;
external 'GDI32.dll' name 'CreateDIBSection';result := DllCall("GDI32\CreateDIBSection"
, "Ptr", hdc ; HDC optional
, "Ptr", pbmi ; BITMAPINFO*
, "UInt", usage ; DIB_USAGE
, "Ptr", ppvBits ; void** out
, "Ptr", hSection ; HANDLE optional
, "UInt", offset ; DWORD
, "Ptr") ; return: HBITMAP●CreateDIBSection(hdc, pbmi, usage, ppvBits, hSection, offset) = DLL("GDI32.dll", "void* CreateDIBSection(void*, void*, dword, void*, void*, dword)")
# 呼び出し: CreateDIBSection(hdc, pbmi, usage, ppvBits, hSection, offset)
# hdc : HDC optional -> "void*"
# pbmi : BITMAPINFO* -> "void*"
# usage : DIB_USAGE -> "dword"
# ppvBits : void** out -> "void*"
# hSection : HANDLE optional -> "void*"
# offset : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。