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

RealGetWindowClassW

関数
ウィンドウの実際のクラス名を取得する(Unicode版)。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (Unicode / -W)
#include <windows.h>

DWORD RealGetWindowClassW(
    HWND hwnd,
    LPWSTR ptszClassName,
    DWORD cchClassNameMax
);

パラメーター

名前方向
hwndHWNDin
ptszClassNameLPWSTRout
cchClassNameMaxDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

// USER32.dll  (Unicode / -W)
#include <windows.h>

DWORD RealGetWindowClassW(
    HWND hwnd,
    LPWSTR ptszClassName,
    DWORD cchClassNameMax
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern uint RealGetWindowClassW(
    IntPtr hwnd,   // HWND
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ptszClassName,   // LPWSTR out
    uint cchClassNameMax   // DWORD
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function RealGetWindowClassW(
    hwnd As IntPtr,   ' HWND
    <MarshalAs(UnmanagedType.LPWStr)> ptszClassName As System.Text.StringBuilder,   ' LPWSTR out
    cchClassNameMax As UInteger   ' DWORD
) As UInteger
End Function
' hwnd : HWND
' ptszClassName : LPWSTR out
' cchClassNameMax : DWORD
Declare PtrSafe Function RealGetWindowClassW Lib "user32" ( _
    ByVal hwnd As LongPtr, _
    ByVal ptszClassName As LongPtr, _
    ByVal cchClassNameMax As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RealGetWindowClassW = ctypes.windll.user32.RealGetWindowClassW
RealGetWindowClassW.restype = wintypes.DWORD
RealGetWindowClassW.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND
    wintypes.LPWSTR,  # ptszClassName : LPWSTR out
    wintypes.DWORD,  # cchClassNameMax : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
RealGetWindowClassW = Fiddle::Function.new(
  lib['RealGetWindowClassW'],
  [
    Fiddle::TYPE_VOIDP,  # hwnd : HWND
    Fiddle::TYPE_VOIDP,  # ptszClassName : LPWSTR out
    -Fiddle::TYPE_INT,  # cchClassNameMax : DWORD
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn RealGetWindowClassW(
        hwnd: *mut core::ffi::c_void,  // HWND
        ptszClassName: *mut u16,  // LPWSTR out
        cchClassNameMax: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint RealGetWindowClassW(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ptszClassName, uint cchClassNameMax);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_RealGetWindowClassW' -Namespace Win32 -PassThru
# $api::RealGetWindowClassW(hwnd, ptszClassName, cchClassNameMax)
#uselib "USER32.dll"
#func global RealGetWindowClassW "RealGetWindowClassW" wptr, wptr, wptr
; RealGetWindowClassW hwnd, varptr(ptszClassName), cchClassNameMax   ; 戻り値は stat
; hwnd : HWND -> "wptr"
; ptszClassName : LPWSTR out -> "wptr"
; cchClassNameMax : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global RealGetWindowClassW "RealGetWindowClassW" sptr, var, int
; res = RealGetWindowClassW(hwnd, ptszClassName, cchClassNameMax)
; hwnd : HWND -> "sptr"
; ptszClassName : LPWSTR out -> "var"
; cchClassNameMax : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD RealGetWindowClassW(HWND hwnd, LPWSTR ptszClassName, DWORD cchClassNameMax)
#uselib "USER32.dll"
#cfunc global RealGetWindowClassW "RealGetWindowClassW" intptr, var, int
; res = RealGetWindowClassW(hwnd, ptszClassName, cchClassNameMax)
; hwnd : HWND -> "intptr"
; ptszClassName : LPWSTR out -> "var"
; cchClassNameMax : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procRealGetWindowClassW = user32.NewProc("RealGetWindowClassW")
)

// hwnd (HWND), ptszClassName (LPWSTR out), cchClassNameMax (DWORD)
r1, _, err := procRealGetWindowClassW.Call(
	uintptr(hwnd),
	uintptr(ptszClassName),
	uintptr(cchClassNameMax),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function RealGetWindowClassW(
  hwnd: THandle;   // HWND
  ptszClassName: PWideChar;   // LPWSTR out
  cchClassNameMax: DWORD   // DWORD
): DWORD; stdcall;
  external 'USER32.dll' name 'RealGetWindowClassW';
result := DllCall("USER32\RealGetWindowClassW"
    , "Ptr", hwnd   ; HWND
    , "Ptr", ptszClassName   ; LPWSTR out
    , "UInt", cchClassNameMax   ; DWORD
    , "UInt")   ; return: DWORD
●RealGetWindowClassW(hwnd, ptszClassName, cchClassNameMax) = DLL("USER32.dll", "dword RealGetWindowClassW(void*, char*, dword)")
# 呼び出し: RealGetWindowClassW(hwnd, ptszClassName, cchClassNameMax)
# hwnd : HWND -> "void*"
# ptszClassName : LPWSTR out -> "char*"
# cchClassNameMax : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。