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

GetDeviceCaps

関数
デバイスの能力や属性情報を取得する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

INT GetDeviceCaps(
    HDC hdc,   // optional
    INT index
);

パラメーター

名前方向
hdcHDCinoptional
indexINTin

戻り値の型: INT

各言語での呼び出し定義

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

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

GetDeviceCaps = ctypes.windll.gdi32.GetDeviceCaps
GetDeviceCaps.restype = ctypes.c_int
GetDeviceCaps.argtypes = [
    wintypes.HANDLE,  # hdc : HDC optional
    ctypes.c_int,  # index : INT
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetDeviceCaps = gdi32.NewProc("GetDeviceCaps")
)

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