Win32 API 日本語リファレンス
ホームSystem.StationsAndDesktops › GetUserObjectInformationW

GetUserObjectInformationW

関数
ウィンドウステーションやデスクトップの情報を取得する。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL GetUserObjectInformationW(
    HANDLE hObj,
    USER_OBJECT_INFORMATION_INDEX nIndex,
    void* pvInfo,   // optional
    DWORD nLength,
    DWORD* lpnLengthNeeded   // optional
);

パラメーター

名前方向説明
hObjHANDLEin情報を取得するユーザーオブジェクト(デスクトップ/ウィンドウステーション)のハンドル。
nIndexUSER_OBJECT_INFORMATION_INDEXin取得する情報の種類。UOI_NAME や UOI_TYPE 等のインデックス値。
pvInfovoid*outoptional結果(Unicode 文字列等)を受け取るバッファへのポインタ。
nLengthDWORDinpvInfo バッファのサイズ(バイト単位)。
lpnLengthNeededDWORD*outoptional必要なバイト数を受け取るポインタ。不要なら NULL 可。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetUserObjectInformationW(
    HANDLE hObj,
    USER_OBJECT_INFORMATION_INDEX nIndex,
    void* pvInfo,   // optional
    DWORD nLength,
    DWORD* lpnLengthNeeded   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool GetUserObjectInformationW(
    IntPtr hObj,   // HANDLE
    int nIndex,   // USER_OBJECT_INFORMATION_INDEX
    IntPtr pvInfo,   // void* optional, out
    uint nLength,   // DWORD
    IntPtr lpnLengthNeeded   // DWORD* optional, out
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetUserObjectInformationW(
    hObj As IntPtr,   ' HANDLE
    nIndex As Integer,   ' USER_OBJECT_INFORMATION_INDEX
    pvInfo As IntPtr,   ' void* optional, out
    nLength As UInteger,   ' DWORD
    lpnLengthNeeded As IntPtr   ' DWORD* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hObj : HANDLE
' nIndex : USER_OBJECT_INFORMATION_INDEX
' pvInfo : void* optional, out
' nLength : DWORD
' lpnLengthNeeded : DWORD* optional, out
Declare PtrSafe Function GetUserObjectInformationW Lib "user32" ( _
    ByVal hObj As LongPtr, _
    ByVal nIndex As Long, _
    ByVal pvInfo As LongPtr, _
    ByVal nLength As Long, _
    ByVal lpnLengthNeeded As LongPtr) 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

GetUserObjectInformationW = ctypes.windll.user32.GetUserObjectInformationW
GetUserObjectInformationW.restype = wintypes.BOOL
GetUserObjectInformationW.argtypes = [
    wintypes.HANDLE,  # hObj : HANDLE
    ctypes.c_int,  # nIndex : USER_OBJECT_INFORMATION_INDEX
    ctypes.POINTER(None),  # pvInfo : void* optional, out
    wintypes.DWORD,  # nLength : DWORD
    ctypes.POINTER(wintypes.DWORD),  # lpnLengthNeeded : DWORD* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetUserObjectInformationW = user32.NewProc("GetUserObjectInformationW")
)

// hObj (HANDLE), nIndex (USER_OBJECT_INFORMATION_INDEX), pvInfo (void* optional, out), nLength (DWORD), lpnLengthNeeded (DWORD* optional, out)
r1, _, err := procGetUserObjectInformationW.Call(
	uintptr(hObj),
	uintptr(nIndex),
	uintptr(pvInfo),
	uintptr(nLength),
	uintptr(lpnLengthNeeded),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetUserObjectInformationW(
  hObj: THandle;   // HANDLE
  nIndex: Integer;   // USER_OBJECT_INFORMATION_INDEX
  pvInfo: Pointer;   // void* optional, out
  nLength: DWORD;   // DWORD
  lpnLengthNeeded: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'USER32.dll' name 'GetUserObjectInformationW';
result := DllCall("USER32\GetUserObjectInformationW"
    , "Ptr", hObj   ; HANDLE
    , "Int", nIndex   ; USER_OBJECT_INFORMATION_INDEX
    , "Ptr", pvInfo   ; void* optional, out
    , "UInt", nLength   ; DWORD
    , "Ptr", lpnLengthNeeded   ; DWORD* optional, out
    , "Int")   ; return: BOOL
●GetUserObjectInformationW(hObj, nIndex, pvInfo, nLength, lpnLengthNeeded) = DLL("USER32.dll", "bool GetUserObjectInformationW(void*, int, void*, dword, void*)")
# 呼び出し: GetUserObjectInformationW(hObj, nIndex, pvInfo, nLength, lpnLengthNeeded)
# hObj : HANDLE -> "void*"
# nIndex : USER_OBJECT_INFORMATION_INDEX -> "int"
# pvInfo : void* optional, out -> "void*"
# nLength : DWORD -> "dword"
# lpnLengthNeeded : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "user32" fn GetUserObjectInformationW(
    hObj: ?*anyopaque, // HANDLE
    nIndex: i32, // USER_OBJECT_INFORMATION_INDEX
    pvInfo: ?*anyopaque, // void* optional, out
    nLength: u32, // DWORD
    lpnLengthNeeded: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc GetUserObjectInformationW(
    hObj: pointer,  # HANDLE
    nIndex: int32,  # USER_OBJECT_INFORMATION_INDEX
    pvInfo: pointer,  # void* optional, out
    nLength: uint32,  # DWORD
    lpnLengthNeeded: ptr uint32  # DWORD* optional, out
): int32 {.importc: "GetUserObjectInformationW", stdcall, dynlib: "USER32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "user32");
extern(Windows)
int GetUserObjectInformationW(
    void* hObj,   // HANDLE
    int nIndex,   // USER_OBJECT_INFORMATION_INDEX
    void* pvInfo,   // void* optional, out
    uint nLength,   // DWORD
    uint* lpnLengthNeeded   // DWORD* optional, out
);
ccall((:GetUserObjectInformationW, "USER32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
      hObj, nIndex, pvInfo, nLength, lpnLengthNeeded)
# hObj : HANDLE -> Ptr{Cvoid}
# nIndex : USER_OBJECT_INFORMATION_INDEX -> Int32
# pvInfo : void* optional, out -> Ptr{Cvoid}
# nLength : DWORD -> UInt32
# lpnLengthNeeded : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetUserObjectInformationW(
    void* hObj,
    int32_t nIndex,
    void* pvInfo,
    uint32_t nLength,
    uint32_t* lpnLengthNeeded);
]]
local user32 = ffi.load("user32")
-- user32.GetUserObjectInformationW(hObj, nIndex, pvInfo, nLength, lpnLengthNeeded)
-- hObj : HANDLE
-- nIndex : USER_OBJECT_INFORMATION_INDEX
-- pvInfo : void* optional, out
-- nLength : DWORD
-- lpnLengthNeeded : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const GetUserObjectInformationW = lib.func('__stdcall', 'GetUserObjectInformationW', 'int32_t', ['void *', 'int32_t', 'void *', 'uint32_t', 'uint32_t *']);
// GetUserObjectInformationW(hObj, nIndex, pvInfo, nLength, lpnLengthNeeded)
// hObj : HANDLE -> 'void *'
// nIndex : USER_OBJECT_INFORMATION_INDEX -> 'int32_t'
// pvInfo : void* optional, out -> 'void *'
// nLength : DWORD -> 'uint32_t'
// lpnLengthNeeded : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("USER32.dll", {
  GetUserObjectInformationW: { parameters: ["pointer", "i32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.GetUserObjectInformationW(hObj, nIndex, pvInfo, nLength, lpnLengthNeeded)
// hObj : HANDLE -> "pointer"
// nIndex : USER_OBJECT_INFORMATION_INDEX -> "i32"
// pvInfo : void* optional, out -> "pointer"
// nLength : DWORD -> "u32"
// lpnLengthNeeded : DWORD* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetUserObjectInformationW(
    void* hObj,
    int32_t nIndex,
    void* pvInfo,
    uint32_t nLength,
    uint32_t* lpnLengthNeeded);
C, "USER32.dll");
// $ffi->GetUserObjectInformationW(hObj, nIndex, pvInfo, nLength, lpnLengthNeeded);
// hObj : HANDLE
// nIndex : USER_OBJECT_INFORMATION_INDEX
// pvInfo : void* optional, out
// nLength : DWORD
// lpnLengthNeeded : DWORD* 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 User32 extends StdCallLibrary {
    User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.UNICODE_OPTIONS);
    boolean GetUserObjectInformationW(
        Pointer hObj,   // HANDLE
        int nIndex,   // USER_OBJECT_INFORMATION_INDEX
        Pointer pvInfo,   // void* optional, out
        int nLength,   // DWORD
        IntByReference lpnLengthNeeded   // DWORD* optional, out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("user32")]
lib LibUSER32
  fun GetUserObjectInformationW = GetUserObjectInformationW(
    hObj : Void*,   # HANDLE
    nIndex : Int32,   # USER_OBJECT_INFORMATION_INDEX
    pvInfo : Void*,   # void* optional, out
    nLength : UInt32,   # DWORD
    lpnLengthNeeded : UInt32*   # DWORD* 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 GetUserObjectInformationWNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef GetUserObjectInformationWDart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Uint32>);
final GetUserObjectInformationW = DynamicLibrary.open('USER32.dll')
    .lookupFunction<GetUserObjectInformationWNative, GetUserObjectInformationWDart>('GetUserObjectInformationW');
// hObj : HANDLE -> Pointer<Void>
// nIndex : USER_OBJECT_INFORMATION_INDEX -> Int32
// pvInfo : void* optional, out -> Pointer<Void>
// nLength : DWORD -> Uint32
// lpnLengthNeeded : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetUserObjectInformationW(
  hObj: THandle;   // HANDLE
  nIndex: Integer;   // USER_OBJECT_INFORMATION_INDEX
  pvInfo: Pointer;   // void* optional, out
  nLength: DWORD;   // DWORD
  lpnLengthNeeded: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'USER32.dll' name 'GetUserObjectInformationW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetUserObjectInformationW"
  c_GetUserObjectInformationW :: Ptr () -> Int32 -> Ptr () -> Word32 -> Ptr Word32 -> IO CInt
-- hObj : HANDLE -> Ptr ()
-- nIndex : USER_OBJECT_INFORMATION_INDEX -> Int32
-- pvInfo : void* optional, out -> Ptr ()
-- nLength : DWORD -> Word32
-- lpnLengthNeeded : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getuserobjectinformationw =
  foreign "GetUserObjectInformationW"
    ((ptr void) @-> int32_t @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* hObj : HANDLE -> (ptr void) *)
(* nIndex : USER_OBJECT_INFORMATION_INDEX -> int32_t *)
(* pvInfo : void* optional, out -> (ptr void) *)
(* nLength : DWORD -> uint32_t *)
(* lpnLengthNeeded : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)

(cffi:defcfun ("GetUserObjectInformationW" get-user-object-information-w :convention :stdcall) :int32
  (h-obj :pointer)   ; HANDLE
  (n-index :int32)   ; USER_OBJECT_INFORMATION_INDEX
  (pv-info :pointer)   ; void* optional, out
  (n-length :uint32)   ; DWORD
  (lpn-length-needed :pointer))   ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetUserObjectInformationW = Win32::API::More->new('USER32',
    'BOOL GetUserObjectInformationW(HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPVOID lpnLengthNeeded)');
# my $ret = $GetUserObjectInformationW->Call($hObj, $nIndex, $pvInfo, $nLength, $lpnLengthNeeded);
# hObj : HANDLE -> HANDLE
# nIndex : USER_OBJECT_INFORMATION_INDEX -> int
# pvInfo : void* optional, out -> LPVOID
# nLength : DWORD -> DWORD
# lpnLengthNeeded : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型