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

GetUserObjectInformationA

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

シグネチャ

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

BOOL GetUserObjectInformationA(
    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結果(ANSI 文字列等)を受け取るバッファへのポインタ。
nLengthDWORDinpvInfo バッファのサイズ(バイト単位)。
lpnLengthNeededDWORD*outoptional必要なバイト数を受け取るポインタ。不要なら NULL 可。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetUserObjectInformationA(
    HANDLE hObj,
    USER_OBJECT_INFORMATION_INDEX nIndex,
    void* pvInfo,   // optional
    DWORD nLength,
    DWORD* lpnLengthNeeded   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool GetUserObjectInformationA(
    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.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetUserObjectInformationA(
    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 GetUserObjectInformationA Lib "user32" ( _
    ByVal hObj As LongPtr, _
    ByVal nIndex As Long, _
    ByVal pvInfo As LongPtr, _
    ByVal nLength As Long, _
    ByVal lpnLengthNeeded As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetUserObjectInformationA = ctypes.windll.user32.GetUserObjectInformationA
GetUserObjectInformationA.restype = wintypes.BOOL
GetUserObjectInformationA.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')
GetUserObjectInformationA = Fiddle::Function.new(
  lib['GetUserObjectInformationA'],
  [
    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)
#[link(name = "user32")]
extern "system" {
    fn GetUserObjectInformationA(
        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.Ansi, SetLastError = true)]
public static extern bool GetUserObjectInformationA(IntPtr hObj, int nIndex, IntPtr pvInfo, uint nLength, IntPtr lpnLengthNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetUserObjectInformationA' -Namespace Win32 -PassThru
# $api::GetUserObjectInformationA(hObj, nIndex, pvInfo, nLength, lpnLengthNeeded)
#uselib "USER32.dll"
#func global GetUserObjectInformationA "GetUserObjectInformationA" sptr, sptr, sptr, sptr, sptr
; GetUserObjectInformationA hObj, nIndex, pvInfo, nLength, varptr(lpnLengthNeeded)   ; 戻り値は stat
; hObj : HANDLE -> "sptr"
; nIndex : USER_OBJECT_INFORMATION_INDEX -> "sptr"
; pvInfo : void* optional, out -> "sptr"
; nLength : DWORD -> "sptr"
; lpnLengthNeeded : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global GetUserObjectInformationA "GetUserObjectInformationA" sptr, int, sptr, int, var
; res = GetUserObjectInformationA(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 GetUserObjectInformationA(HANDLE hObj, USER_OBJECT_INFORMATION_INDEX nIndex, void* pvInfo, DWORD nLength, DWORD* lpnLengthNeeded)
#uselib "USER32.dll"
#cfunc global GetUserObjectInformationA "GetUserObjectInformationA" intptr, int, intptr, int, var
; res = GetUserObjectInformationA(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")
	procGetUserObjectInformationA = user32.NewProc("GetUserObjectInformationA")
)

// hObj (HANDLE), nIndex (USER_OBJECT_INFORMATION_INDEX), pvInfo (void* optional, out), nLength (DWORD), lpnLengthNeeded (DWORD* optional, out)
r1, _, err := procGetUserObjectInformationA.Call(
	uintptr(hObj),
	uintptr(nIndex),
	uintptr(pvInfo),
	uintptr(nLength),
	uintptr(lpnLengthNeeded),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetUserObjectInformationA(
  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 'GetUserObjectInformationA';
result := DllCall("USER32\GetUserObjectInformationA"
    , "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
●GetUserObjectInformationA(hObj, nIndex, pvInfo, nLength, lpnLengthNeeded) = DLL("USER32.dll", "bool GetUserObjectInformationA(void*, int, void*, dword, void*)")
# 呼び出し: GetUserObjectInformationA(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)。
const std = @import("std");

extern "user32" fn GetUserObjectInformationA(
    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;
proc GetUserObjectInformationA(
    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: "GetUserObjectInformationA", stdcall, dynlib: "USER32.dll".}
pragma(lib, "user32");
extern(Windows)
int GetUserObjectInformationA(
    void* hObj,   // HANDLE
    int nIndex,   // USER_OBJECT_INFORMATION_INDEX
    void* pvInfo,   // void* optional, out
    uint nLength,   // DWORD
    uint* lpnLengthNeeded   // DWORD* optional, out
);
ccall((:GetUserObjectInformationA, "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 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetUserObjectInformationA(
    void* hObj,
    int32_t nIndex,
    void* pvInfo,
    uint32_t nLength,
    uint32_t* lpnLengthNeeded);
]]
local user32 = ffi.load("user32")
-- user32.GetUserObjectInformationA(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 に追加すること。
const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const GetUserObjectInformationA = lib.func('__stdcall', 'GetUserObjectInformationA', 'int32_t', ['void *', 'int32_t', 'void *', 'uint32_t', 'uint32_t *']);
// GetUserObjectInformationA(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", {
  GetUserObjectInformationA: { parameters: ["pointer", "i32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.GetUserObjectInformationA(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"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetUserObjectInformationA(
    void* hObj,
    int32_t nIndex,
    void* pvInfo,
    uint32_t nLength,
    uint32_t* lpnLengthNeeded);
C, "USER32.dll");
// $ffi->GetUserObjectInformationA(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.ASCII_OPTIONS);
    boolean GetUserObjectInformationA(
        Pointer hObj,   // HANDLE
        int nIndex,   // USER_OBJECT_INFORMATION_INDEX
        Pointer pvInfo,   // void* optional, out
        int nLength,   // DWORD
        IntByReference lpnLengthNeeded   // DWORD* optional, out
    );
}
@[Link("user32")]
lib LibUSER32
  fun GetUserObjectInformationA = GetUserObjectInformationA(
    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 GetUserObjectInformationANative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef GetUserObjectInformationADart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Uint32>);
final GetUserObjectInformationA = DynamicLibrary.open('USER32.dll')
    .lookupFunction<GetUserObjectInformationANative, GetUserObjectInformationADart>('GetUserObjectInformationA');
// 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 GetUserObjectInformationA(
  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 'GetUserObjectInformationA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetUserObjectInformationA"
  c_GetUserObjectInformationA :: 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 getuserobjectinformationa =
  foreign "GetUserObjectInformationA"
    ((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 ("GetUserObjectInformationA" get-user-object-information-a :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 $GetUserObjectInformationA = Win32::API::More->new('USER32',
    'BOOL GetUserObjectInformationA(HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPVOID lpnLengthNeeded)');
# my $ret = $GetUserObjectInformationA->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 を使用。

関連項目

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