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

GetWindowLongPtrA

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

シグネチャ

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

INT_PTR GetWindowLongPtrA(
    HWND hWnd,
    WINDOW_LONG_PTR_INDEX nIndex
);

パラメーター

名前方向
hWndHWNDin
nIndexWINDOW_LONG_PTR_INDEXin

戻り値の型: INT_PTR

各言語での呼び出し定義

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

INT_PTR GetWindowLongPtrA(
    HWND hWnd,
    WINDOW_LONG_PTR_INDEX nIndex
);
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr GetWindowLongPtrA(
    IntPtr hWnd,   // HWND
    int nIndex   // WINDOW_LONG_PTR_INDEX
);
<DllImport("USER32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetWindowLongPtrA(
    hWnd As IntPtr,   ' HWND
    nIndex As Integer   ' WINDOW_LONG_PTR_INDEX
) As IntPtr
End Function
' hWnd : HWND
' nIndex : WINDOW_LONG_PTR_INDEX
Declare PtrSafe Function GetWindowLongPtrA 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

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

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetWindowLongPtrA = user32.NewProc("GetWindowLongPtrA")
)

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