Win32 API 日本語リファレンス
ホームUI.WindowsAndMessaging › GetClassLongPtrA

GetClassLongPtrA

関数
ウィンドウクラスの情報をポインタ幅で取得する(ANSI)。
DLLUSER32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (ANSI / -A)
#include <windows.h>

UINT_PTR GetClassLongPtrA(
    HWND hWnd,
    GET_CLASS_LONG_INDEX nIndex
);

パラメーター

名前方向
hWndHWNDin
nIndexGET_CLASS_LONG_INDEXin

戻り値の型: UINT_PTR

各言語での呼び出し定義

// USER32.dll  (ANSI / -A)
#include <windows.h>

UINT_PTR GetClassLongPtrA(
    HWND hWnd,
    GET_CLASS_LONG_INDEX nIndex
);
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern UIntPtr GetClassLongPtrA(
    IntPtr hWnd,   // HWND
    int nIndex   // GET_CLASS_LONG_INDEX
);
<DllImport("USER32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetClassLongPtrA(
    hWnd As IntPtr,   ' HWND
    nIndex As Integer   ' GET_CLASS_LONG_INDEX
) As UIntPtr
End Function
' hWnd : HWND
' nIndex : GET_CLASS_LONG_INDEX
Declare PtrSafe Function GetClassLongPtrA Lib "user32" ( _
    ByVal hWnd As LongPtr, _
    ByVal nIndex As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetClassLongPtrA = ctypes.windll.user32.GetClassLongPtrA
GetClassLongPtrA.restype = ctypes.c_size_t
GetClassLongPtrA.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    ctypes.c_int,  # nIndex : GET_CLASS_LONG_INDEX
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
GetClassLongPtrA = Fiddle::Function.new(
  lib['GetClassLongPtrA'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    Fiddle::TYPE_INT,  # nIndex : GET_CLASS_LONG_INDEX
  ],
  Fiddle::TYPE_UINTPTR_T)
#[link(name = "user32")]
extern "system" {
    fn GetClassLongPtrA(
        hWnd: *mut core::ffi::c_void,  // HWND
        nIndex: i32  // GET_CLASS_LONG_INDEX
    ) -> usize;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern UIntPtr GetClassLongPtrA(IntPtr hWnd, int nIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetClassLongPtrA' -Namespace Win32 -PassThru
# $api::GetClassLongPtrA(hWnd, nIndex)
#uselib "USER32.dll"
#func global GetClassLongPtrA "GetClassLongPtrA" sptr, sptr
; GetClassLongPtrA hWnd, nIndex   ; 戻り値は stat
; hWnd : HWND -> "sptr"
; nIndex : GET_CLASS_LONG_INDEX -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global GetClassLongPtrA "GetClassLongPtrA" sptr, int
; res = GetClassLongPtrA(hWnd, nIndex)
; hWnd : HWND -> "sptr"
; nIndex : GET_CLASS_LONG_INDEX -> "int"
; UINT_PTR GetClassLongPtrA(HWND hWnd, GET_CLASS_LONG_INDEX nIndex)
#uselib "USER32.dll"
#cfunc global GetClassLongPtrA "GetClassLongPtrA" intptr, int
; res = GetClassLongPtrA(hWnd, nIndex)
; hWnd : HWND -> "intptr"
; nIndex : GET_CLASS_LONG_INDEX -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetClassLongPtrA = user32.NewProc("GetClassLongPtrA")
)

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