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

SetProcessInformation

関数
指定プロセスの情報をクラス指定で設定する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSwindows8.0

シグネチャ

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

BOOL SetProcessInformation(
    HANDLE hProcess,
    PROCESS_INFORMATION_CLASS ProcessInformationClass,
    void* ProcessInformation,
    DWORD ProcessInformationSize
);

パラメーター

名前方向
hProcessHANDLEin
ProcessInformationClassPROCESS_INFORMATION_CLASSin
ProcessInformationvoid*in
ProcessInformationSizeDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetProcessInformation(
    HANDLE hProcess,
    PROCESS_INFORMATION_CLASS ProcessInformationClass,
    void* ProcessInformation,
    DWORD ProcessInformationSize
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetProcessInformation(
    IntPtr hProcess,   // HANDLE
    int ProcessInformationClass,   // PROCESS_INFORMATION_CLASS
    IntPtr ProcessInformation,   // void*
    uint ProcessInformationSize   // DWORD
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetProcessInformation(
    hProcess As IntPtr,   ' HANDLE
    ProcessInformationClass As Integer,   ' PROCESS_INFORMATION_CLASS
    ProcessInformation As IntPtr,   ' void*
    ProcessInformationSize As UInteger   ' DWORD
) As Boolean
End Function
' hProcess : HANDLE
' ProcessInformationClass : PROCESS_INFORMATION_CLASS
' ProcessInformation : void*
' ProcessInformationSize : DWORD
Declare PtrSafe Function SetProcessInformation Lib "kernel32" ( _
    ByVal hProcess As LongPtr, _
    ByVal ProcessInformationClass As Long, _
    ByVal ProcessInformation As LongPtr, _
    ByVal ProcessInformationSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetProcessInformation = ctypes.windll.kernel32.SetProcessInformation
SetProcessInformation.restype = wintypes.BOOL
SetProcessInformation.argtypes = [
    wintypes.HANDLE,  # hProcess : HANDLE
    ctypes.c_int,  # ProcessInformationClass : PROCESS_INFORMATION_CLASS
    ctypes.POINTER(None),  # ProcessInformation : void*
    wintypes.DWORD,  # ProcessInformationSize : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetProcessInformation = Fiddle::Function.new(
  lib['SetProcessInformation'],
  [
    Fiddle::TYPE_VOIDP,  # hProcess : HANDLE
    Fiddle::TYPE_INT,  # ProcessInformationClass : PROCESS_INFORMATION_CLASS
    Fiddle::TYPE_VOIDP,  # ProcessInformation : void*
    -Fiddle::TYPE_INT,  # ProcessInformationSize : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SetProcessInformation(
        hProcess: *mut core::ffi::c_void,  // HANDLE
        ProcessInformationClass: i32,  // PROCESS_INFORMATION_CLASS
        ProcessInformation: *mut (),  // void*
        ProcessInformationSize: u32  // DWORD
    ) -> 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 SetProcessInformation(IntPtr hProcess, int ProcessInformationClass, IntPtr ProcessInformation, uint ProcessInformationSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetProcessInformation' -Namespace Win32 -PassThru
# $api::SetProcessInformation(hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize)
#uselib "KERNEL32.dll"
#func global SetProcessInformation "SetProcessInformation" sptr, sptr, sptr, sptr
; SetProcessInformation hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize   ; 戻り値は stat
; hProcess : HANDLE -> "sptr"
; ProcessInformationClass : PROCESS_INFORMATION_CLASS -> "sptr"
; ProcessInformation : void* -> "sptr"
; ProcessInformationSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetProcessInformation "SetProcessInformation" sptr, int, sptr, int
; res = SetProcessInformation(hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize)
; hProcess : HANDLE -> "sptr"
; ProcessInformationClass : PROCESS_INFORMATION_CLASS -> "int"
; ProcessInformation : void* -> "sptr"
; ProcessInformationSize : DWORD -> "int"
; BOOL SetProcessInformation(HANDLE hProcess, PROCESS_INFORMATION_CLASS ProcessInformationClass, void* ProcessInformation, DWORD ProcessInformationSize)
#uselib "KERNEL32.dll"
#cfunc global SetProcessInformation "SetProcessInformation" intptr, int, intptr, int
; res = SetProcessInformation(hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize)
; hProcess : HANDLE -> "intptr"
; ProcessInformationClass : PROCESS_INFORMATION_CLASS -> "int"
; ProcessInformation : void* -> "intptr"
; ProcessInformationSize : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetProcessInformation = kernel32.NewProc("SetProcessInformation")
)

// hProcess (HANDLE), ProcessInformationClass (PROCESS_INFORMATION_CLASS), ProcessInformation (void*), ProcessInformationSize (DWORD)
r1, _, err := procSetProcessInformation.Call(
	uintptr(hProcess),
	uintptr(ProcessInformationClass),
	uintptr(ProcessInformation),
	uintptr(ProcessInformationSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetProcessInformation(
  hProcess: THandle;   // HANDLE
  ProcessInformationClass: Integer;   // PROCESS_INFORMATION_CLASS
  ProcessInformation: Pointer;   // void*
  ProcessInformationSize: DWORD   // DWORD
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetProcessInformation';
result := DllCall("KERNEL32\SetProcessInformation"
    , "Ptr", hProcess   ; HANDLE
    , "Int", ProcessInformationClass   ; PROCESS_INFORMATION_CLASS
    , "Ptr", ProcessInformation   ; void*
    , "UInt", ProcessInformationSize   ; DWORD
    , "Int")   ; return: BOOL
●SetProcessInformation(hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize) = DLL("KERNEL32.dll", "bool SetProcessInformation(void*, int, void*, dword)")
# 呼び出し: SetProcessInformation(hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize)
# hProcess : HANDLE -> "void*"
# ProcessInformationClass : PROCESS_INFORMATION_CLASS -> "int"
# ProcessInformation : void* -> "void*"
# ProcessInformationSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。