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

DescribePixelFormat

関数
指定したピクセル形式の詳細情報を取得する。
DLLGDI32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

INT DescribePixelFormat(
    HDC hdc,
    INT iPixelFormat,
    DWORD nBytes,
    PIXELFORMATDESCRIPTOR* ppfd   // optional
);

パラメーター

名前方向説明
hdcHDCin対象のデバイスコンテキストハンドル(HDC)。
iPixelFormatINTin情報を取得するピクセル形式のインデックス番号を示すINT値(1始まり)。
nBytesDWORDinppfdバッファのバイトサイズを示すDWORD値。
ppfdPIXELFORMATDESCRIPTOR*outoptionalピクセル形式の詳細を受け取る出力先のPIXELFORMATDESCRIPTORへのポインタ。NULLで形式数照会。

戻り値の型: INT

各言語での呼び出し定義

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

INT DescribePixelFormat(
    HDC hdc,
    INT iPixelFormat,
    DWORD nBytes,
    PIXELFORMATDESCRIPTOR* ppfd   // optional
);
[DllImport("GDI32.dll", SetLastError = true, ExactSpelling = true)]
static extern int DescribePixelFormat(
    IntPtr hdc,   // HDC
    int iPixelFormat,   // INT
    uint nBytes,   // DWORD
    IntPtr ppfd   // PIXELFORMATDESCRIPTOR* optional, out
);
<DllImport("GDI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DescribePixelFormat(
    hdc As IntPtr,   ' HDC
    iPixelFormat As Integer,   ' INT
    nBytes As UInteger,   ' DWORD
    ppfd As IntPtr   ' PIXELFORMATDESCRIPTOR* optional, out
) As Integer
End Function
' hdc : HDC
' iPixelFormat : INT
' nBytes : DWORD
' ppfd : PIXELFORMATDESCRIPTOR* optional, out
Declare PtrSafe Function DescribePixelFormat Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal iPixelFormat As Long, _
    ByVal nBytes As Long, _
    ByVal ppfd As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DescribePixelFormat = ctypes.windll.gdi32.DescribePixelFormat
DescribePixelFormat.restype = ctypes.c_int
DescribePixelFormat.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # iPixelFormat : INT
    wintypes.DWORD,  # nBytes : DWORD
    ctypes.c_void_p,  # ppfd : PIXELFORMATDESCRIPTOR* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procDescribePixelFormat = gdi32.NewProc("DescribePixelFormat")
)

// hdc (HDC), iPixelFormat (INT), nBytes (DWORD), ppfd (PIXELFORMATDESCRIPTOR* optional, out)
r1, _, err := procDescribePixelFormat.Call(
	uintptr(hdc),
	uintptr(iPixelFormat),
	uintptr(nBytes),
	uintptr(ppfd),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function DescribePixelFormat(
  hdc: THandle;   // HDC
  iPixelFormat: Integer;   // INT
  nBytes: DWORD;   // DWORD
  ppfd: Pointer   // PIXELFORMATDESCRIPTOR* optional, out
): Integer; stdcall;
  external 'GDI32.dll' name 'DescribePixelFormat';
result := DllCall("GDI32\DescribePixelFormat"
    , "Ptr", hdc   ; HDC
    , "Int", iPixelFormat   ; INT
    , "UInt", nBytes   ; DWORD
    , "Ptr", ppfd   ; PIXELFORMATDESCRIPTOR* optional, out
    , "Int")   ; return: INT
●DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd) = DLL("GDI32.dll", "int DescribePixelFormat(void*, int, dword, void*)")
# 呼び出し: DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd)
# hdc : HDC -> "void*"
# iPixelFormat : INT -> "int"
# nBytes : DWORD -> "dword"
# ppfd : PIXELFORMATDESCRIPTOR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "gdi32" fn DescribePixelFormat(
    hdc: ?*anyopaque, // HDC
    iPixelFormat: i32, // INT
    nBytes: u32, // DWORD
    ppfd: [*c]PIXELFORMATDESCRIPTOR // PIXELFORMATDESCRIPTOR* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc DescribePixelFormat(
    hdc: pointer,  # HDC
    iPixelFormat: int32,  # INT
    nBytes: uint32,  # DWORD
    ppfd: ptr PIXELFORMATDESCRIPTOR  # PIXELFORMATDESCRIPTOR* optional, out
): int32 {.importc: "DescribePixelFormat", stdcall, dynlib: "GDI32.dll".}
pragma(lib, "gdi32");
extern(Windows)
int DescribePixelFormat(
    void* hdc,   // HDC
    int iPixelFormat,   // INT
    uint nBytes,   // DWORD
    PIXELFORMATDESCRIPTOR* ppfd   // PIXELFORMATDESCRIPTOR* optional, out
);
ccall((:DescribePixelFormat, "GDI32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, UInt32, Ptr{PIXELFORMATDESCRIPTOR}),
      hdc, iPixelFormat, nBytes, ppfd)
# hdc : HDC -> Ptr{Cvoid}
# iPixelFormat : INT -> Int32
# nBytes : DWORD -> UInt32
# ppfd : PIXELFORMATDESCRIPTOR* optional, out -> Ptr{PIXELFORMATDESCRIPTOR}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t DescribePixelFormat(
    void* hdc,
    int32_t iPixelFormat,
    uint32_t nBytes,
    void* ppfd);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd)
-- hdc : HDC
-- iPixelFormat : INT
-- nBytes : DWORD
-- ppfd : PIXELFORMATDESCRIPTOR* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const DescribePixelFormat = lib.func('__stdcall', 'DescribePixelFormat', 'int32_t', ['void *', 'int32_t', 'uint32_t', 'void *']);
// DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd)
// hdc : HDC -> 'void *'
// iPixelFormat : INT -> 'int32_t'
// nBytes : DWORD -> 'uint32_t'
// ppfd : PIXELFORMATDESCRIPTOR* optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("GDI32.dll", {
  DescribePixelFormat: { parameters: ["pointer", "i32", "u32", "pointer"], result: "i32" },
});
// lib.symbols.DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd)
// hdc : HDC -> "pointer"
// iPixelFormat : INT -> "i32"
// nBytes : DWORD -> "u32"
// ppfd : PIXELFORMATDESCRIPTOR* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t DescribePixelFormat(
    void* hdc,
    int32_t iPixelFormat,
    uint32_t nBytes,
    void* ppfd);
C, "GDI32.dll");
// $ffi->DescribePixelFormat(hdc, iPixelFormat, nBytes, ppfd);
// hdc : HDC
// iPixelFormat : INT
// nBytes : DWORD
// ppfd : PIXELFORMATDESCRIPTOR* optional, out
// 構造体/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 DescribePixelFormat(
        Pointer hdc,   // HDC
        int iPixelFormat,   // INT
        int nBytes,   // DWORD
        Pointer ppfd   // PIXELFORMATDESCRIPTOR* optional, out
    );
}
@[Link("gdi32")]
lib LibGDI32
  fun DescribePixelFormat = DescribePixelFormat(
    hdc : Void*,   # HDC
    iPixelFormat : Int32,   # INT
    nBytes : UInt32,   # DWORD
    ppfd : PIXELFORMATDESCRIPTOR*   # PIXELFORMATDESCRIPTOR* optional, out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef DescribePixelFormatNative = Int32 Function(Pointer<Void>, Int32, Uint32, Pointer<Void>);
typedef DescribePixelFormatDart = int Function(Pointer<Void>, int, int, Pointer<Void>);
final DescribePixelFormat = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<DescribePixelFormatNative, DescribePixelFormatDart>('DescribePixelFormat');
// hdc : HDC -> Pointer<Void>
// iPixelFormat : INT -> Int32
// nBytes : DWORD -> Uint32
// ppfd : PIXELFORMATDESCRIPTOR* optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DescribePixelFormat(
  hdc: THandle;   // HDC
  iPixelFormat: Integer;   // INT
  nBytes: DWORD;   // DWORD
  ppfd: Pointer   // PIXELFORMATDESCRIPTOR* optional, out
): Integer; stdcall;
  external 'GDI32.dll' name 'DescribePixelFormat';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DescribePixelFormat"
  c_DescribePixelFormat :: Ptr () -> Int32 -> Word32 -> Ptr () -> IO Int32
-- hdc : HDC -> Ptr ()
-- iPixelFormat : INT -> Int32
-- nBytes : DWORD -> Word32
-- ppfd : PIXELFORMATDESCRIPTOR* optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let describepixelformat =
  foreign "DescribePixelFormat"
    ((ptr void) @-> int32_t @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* iPixelFormat : INT -> int32_t *)
(* nBytes : DWORD -> uint32_t *)
(* ppfd : PIXELFORMATDESCRIPTOR* optional, out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("DescribePixelFormat" describe-pixel-format :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (i-pixel-format :int32)   ; INT
  (n-bytes :uint32)   ; DWORD
  (ppfd :pointer))   ; PIXELFORMATDESCRIPTOR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DescribePixelFormat = Win32::API::More->new('GDI32',
    'int DescribePixelFormat(HANDLE hdc, int iPixelFormat, DWORD nBytes, LPVOID ppfd)');
# my $ret = $DescribePixelFormat->Call($hdc, $iPixelFormat, $nBytes, $ppfd);
# hdc : HDC -> HANDLE
# iPixelFormat : INT -> int
# nBytes : DWORD -> DWORD
# ppfd : PIXELFORMATDESCRIPTOR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型