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

UpdateProcThreadAttribute

関数
プロセス/スレッド属性リストに属性を設定する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// KERNEL32.dll
#include <windows.h>

BOOL UpdateProcThreadAttribute(
    LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList,
    DWORD dwFlags,
    UINT_PTR Attribute,
    void* lpValue,   // optional
    UINT_PTR cbSize,
    void* lpPreviousValue,   // optional
    UINT_PTR* lpReturnSize   // optional
);

パラメーター

名前方向
lpAttributeListLPPROC_THREAD_ATTRIBUTE_LISTinout
dwFlagsDWORDin
AttributeUINT_PTRin
lpValuevoid*inoptional
cbSizeUINT_PTRin
lpPreviousValuevoid*outoptional
lpReturnSizeUINT_PTR*inoptional

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

BOOL UpdateProcThreadAttribute(
    LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList,
    DWORD dwFlags,
    UINT_PTR Attribute,
    void* lpValue,   // optional
    UINT_PTR cbSize,
    void* lpPreviousValue,   // optional
    UINT_PTR* lpReturnSize   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool UpdateProcThreadAttribute(
    IntPtr lpAttributeList,   // LPPROC_THREAD_ATTRIBUTE_LIST in/out
    uint dwFlags,   // DWORD
    UIntPtr Attribute,   // UINT_PTR
    IntPtr lpValue,   // void* optional
    UIntPtr cbSize,   // UINT_PTR
    IntPtr lpPreviousValue,   // void* optional, out
    IntPtr lpReturnSize   // UINT_PTR* optional
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function UpdateProcThreadAttribute(
    lpAttributeList As IntPtr,   ' LPPROC_THREAD_ATTRIBUTE_LIST in/out
    dwFlags As UInteger,   ' DWORD
    Attribute As UIntPtr,   ' UINT_PTR
    lpValue As IntPtr,   ' void* optional
    cbSize As UIntPtr,   ' UINT_PTR
    lpPreviousValue As IntPtr,   ' void* optional, out
    lpReturnSize As IntPtr   ' UINT_PTR* optional
) As Boolean
End Function
' lpAttributeList : LPPROC_THREAD_ATTRIBUTE_LIST in/out
' dwFlags : DWORD
' Attribute : UINT_PTR
' lpValue : void* optional
' cbSize : UINT_PTR
' lpPreviousValue : void* optional, out
' lpReturnSize : UINT_PTR* optional
Declare PtrSafe Function UpdateProcThreadAttribute Lib "kernel32" ( _
    ByVal lpAttributeList As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal Attribute As LongPtr, _
    ByVal lpValue As LongPtr, _
    ByVal cbSize As LongPtr, _
    ByVal lpPreviousValue As LongPtr, _
    ByVal lpReturnSize As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

UpdateProcThreadAttribute = ctypes.windll.kernel32.UpdateProcThreadAttribute
UpdateProcThreadAttribute.restype = wintypes.BOOL
UpdateProcThreadAttribute.argtypes = [
    wintypes.HANDLE,  # lpAttributeList : LPPROC_THREAD_ATTRIBUTE_LIST in/out
    wintypes.DWORD,  # dwFlags : DWORD
    ctypes.c_size_t,  # Attribute : UINT_PTR
    ctypes.POINTER(None),  # lpValue : void* optional
    ctypes.c_size_t,  # cbSize : UINT_PTR
    ctypes.POINTER(None),  # lpPreviousValue : void* optional, out
    ctypes.POINTER(ctypes.c_size_t),  # lpReturnSize : UINT_PTR* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
UpdateProcThreadAttribute = Fiddle::Function.new(
  lib['UpdateProcThreadAttribute'],
  [
    Fiddle::TYPE_VOIDP,  # lpAttributeList : LPPROC_THREAD_ATTRIBUTE_LIST in/out
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_UINTPTR_T,  # Attribute : UINT_PTR
    Fiddle::TYPE_VOIDP,  # lpValue : void* optional
    Fiddle::TYPE_UINTPTR_T,  # cbSize : UINT_PTR
    Fiddle::TYPE_VOIDP,  # lpPreviousValue : void* optional, out
    Fiddle::TYPE_VOIDP,  # lpReturnSize : UINT_PTR* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn UpdateProcThreadAttribute(
        lpAttributeList: *mut core::ffi::c_void,  // LPPROC_THREAD_ATTRIBUTE_LIST in/out
        dwFlags: u32,  // DWORD
        Attribute: usize,  // UINT_PTR
        lpValue: *mut (),  // void* optional
        cbSize: usize,  // UINT_PTR
        lpPreviousValue: *mut (),  // void* optional, out
        lpReturnSize: *mut usize  // UINT_PTR* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool UpdateProcThreadAttribute(IntPtr lpAttributeList, uint dwFlags, UIntPtr Attribute, IntPtr lpValue, UIntPtr cbSize, IntPtr lpPreviousValue, IntPtr lpReturnSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_UpdateProcThreadAttribute' -Namespace Win32 -PassThru
# $api::UpdateProcThreadAttribute(lpAttributeList, dwFlags, Attribute, lpValue, cbSize, lpPreviousValue, lpReturnSize)
#uselib "KERNEL32.dll"
#func global UpdateProcThreadAttribute "UpdateProcThreadAttribute" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; UpdateProcThreadAttribute lpAttributeList, dwFlags, Attribute, lpValue, cbSize, lpPreviousValue, varptr(lpReturnSize)   ; 戻り値は stat
; lpAttributeList : LPPROC_THREAD_ATTRIBUTE_LIST in/out -> "sptr"
; dwFlags : DWORD -> "sptr"
; Attribute : UINT_PTR -> "sptr"
; lpValue : void* optional -> "sptr"
; cbSize : UINT_PTR -> "sptr"
; lpPreviousValue : void* optional, out -> "sptr"
; lpReturnSize : UINT_PTR* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global UpdateProcThreadAttribute "UpdateProcThreadAttribute" sptr, int, sptr, sptr, sptr, sptr, var
; res = UpdateProcThreadAttribute(lpAttributeList, dwFlags, Attribute, lpValue, cbSize, lpPreviousValue, lpReturnSize)
; lpAttributeList : LPPROC_THREAD_ATTRIBUTE_LIST in/out -> "sptr"
; dwFlags : DWORD -> "int"
; Attribute : UINT_PTR -> "sptr"
; lpValue : void* optional -> "sptr"
; cbSize : UINT_PTR -> "sptr"
; lpPreviousValue : void* optional, out -> "sptr"
; lpReturnSize : UINT_PTR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL UpdateProcThreadAttribute(LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, DWORD dwFlags, UINT_PTR Attribute, void* lpValue, UINT_PTR cbSize, void* lpPreviousValue, UINT_PTR* lpReturnSize)
#uselib "KERNEL32.dll"
#cfunc global UpdateProcThreadAttribute "UpdateProcThreadAttribute" intptr, int, intptr, intptr, intptr, intptr, var
; res = UpdateProcThreadAttribute(lpAttributeList, dwFlags, Attribute, lpValue, cbSize, lpPreviousValue, lpReturnSize)
; lpAttributeList : LPPROC_THREAD_ATTRIBUTE_LIST in/out -> "intptr"
; dwFlags : DWORD -> "int"
; Attribute : UINT_PTR -> "intptr"
; lpValue : void* optional -> "intptr"
; cbSize : UINT_PTR -> "intptr"
; lpPreviousValue : void* optional, out -> "intptr"
; lpReturnSize : UINT_PTR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procUpdateProcThreadAttribute = kernel32.NewProc("UpdateProcThreadAttribute")
)

// lpAttributeList (LPPROC_THREAD_ATTRIBUTE_LIST in/out), dwFlags (DWORD), Attribute (UINT_PTR), lpValue (void* optional), cbSize (UINT_PTR), lpPreviousValue (void* optional, out), lpReturnSize (UINT_PTR* optional)
r1, _, err := procUpdateProcThreadAttribute.Call(
	uintptr(lpAttributeList),
	uintptr(dwFlags),
	uintptr(Attribute),
	uintptr(lpValue),
	uintptr(cbSize),
	uintptr(lpPreviousValue),
	uintptr(lpReturnSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function UpdateProcThreadAttribute(
  lpAttributeList: THandle;   // LPPROC_THREAD_ATTRIBUTE_LIST in/out
  dwFlags: DWORD;   // DWORD
  Attribute: NativeUInt;   // UINT_PTR
  lpValue: Pointer;   // void* optional
  cbSize: NativeUInt;   // UINT_PTR
  lpPreviousValue: Pointer;   // void* optional, out
  lpReturnSize: Pointer   // UINT_PTR* optional
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'UpdateProcThreadAttribute';
result := DllCall("KERNEL32\UpdateProcThreadAttribute"
    , "Ptr", lpAttributeList   ; LPPROC_THREAD_ATTRIBUTE_LIST in/out
    , "UInt", dwFlags   ; DWORD
    , "UPtr", Attribute   ; UINT_PTR
    , "Ptr", lpValue   ; void* optional
    , "UPtr", cbSize   ; UINT_PTR
    , "Ptr", lpPreviousValue   ; void* optional, out
    , "Ptr", lpReturnSize   ; UINT_PTR* optional
    , "Int")   ; return: BOOL
●UpdateProcThreadAttribute(lpAttributeList, dwFlags, Attribute, lpValue, cbSize, lpPreviousValue, lpReturnSize) = DLL("KERNEL32.dll", "bool UpdateProcThreadAttribute(void*, dword, int, void*, int, void*, void*)")
# 呼び出し: UpdateProcThreadAttribute(lpAttributeList, dwFlags, Attribute, lpValue, cbSize, lpPreviousValue, lpReturnSize)
# lpAttributeList : LPPROC_THREAD_ATTRIBUTE_LIST in/out -> "void*"
# dwFlags : DWORD -> "dword"
# Attribute : UINT_PTR -> "int"
# lpValue : void* optional -> "void*"
# cbSize : UINT_PTR -> "int"
# lpPreviousValue : void* optional, out -> "void*"
# lpReturnSize : UINT_PTR* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。