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

SetInformationJobObject

関数
ジョブオブジェクトに制限や情報を設定する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetInformationJobObject(
    HANDLE hJob,
    JOBOBJECTINFOCLASS JobObjectInformationClass,
    void* lpJobObjectInformation,
    DWORD cbJobObjectInformationLength
);

パラメーター

名前方向説明
hJobHANDLEin情報を設定する対象ジョブのハンドル。JOB_OBJECT_SET_ATTRIBUTES権限が必要。
JobObjectInformationClassJOBOBJECTINFOCLASSin設定する情報の種類を示す列挙値。制限情報やUI制限など構造体の型を決める。
lpJobObjectInformationvoid*in設定する情報を格納した構造体へのポインタ。クラスに対応した型を渡す。
cbJobObjectInformationLengthDWORDinlpJobObjectInformationが指す構造体のサイズ(バイト単位)。

戻り値の型: BOOL

各言語での呼び出し定義

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

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

SetInformationJobObject = ctypes.windll.kernel32.SetInformationJobObject
SetInformationJobObject.restype = wintypes.BOOL
SetInformationJobObject.argtypes = [
    wintypes.HANDLE,  # hJob : HANDLE
    ctypes.c_int,  # JobObjectInformationClass : JOBOBJECTINFOCLASS
    ctypes.POINTER(None),  # lpJobObjectInformation : void*
    wintypes.DWORD,  # cbJobObjectInformationLength : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetInformationJobObject = kernel32.NewProc("SetInformationJobObject")
)

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

extern "kernel32" fn SetInformationJobObject(
    hJob: ?*anyopaque, // HANDLE
    JobObjectInformationClass: i32, // JOBOBJECTINFOCLASS
    lpJobObjectInformation: ?*anyopaque, // void*
    cbJobObjectInformationLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc SetInformationJobObject(
    hJob: pointer,  # HANDLE
    JobObjectInformationClass: int32,  # JOBOBJECTINFOCLASS
    lpJobObjectInformation: pointer,  # void*
    cbJobObjectInformationLength: uint32  # DWORD
): int32 {.importc: "SetInformationJobObject", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int SetInformationJobObject(
    void* hJob,   // HANDLE
    int JobObjectInformationClass,   // JOBOBJECTINFOCLASS
    void* lpJobObjectInformation,   // void*
    uint cbJobObjectInformationLength   // DWORD
);
ccall((:SetInformationJobObject, "KERNEL32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Ptr{Cvoid}, UInt32),
      hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength)
# hJob : HANDLE -> Ptr{Cvoid}
# JobObjectInformationClass : JOBOBJECTINFOCLASS -> Int32
# lpJobObjectInformation : void* -> Ptr{Cvoid}
# cbJobObjectInformationLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetInformationJobObject(
    void* hJob,
    int32_t JobObjectInformationClass,
    void* lpJobObjectInformation,
    uint32_t cbJobObjectInformationLength);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.SetInformationJobObject(hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength)
-- hJob : HANDLE
-- JobObjectInformationClass : JOBOBJECTINFOCLASS
-- lpJobObjectInformation : void*
-- cbJobObjectInformationLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const SetInformationJobObject = lib.func('__stdcall', 'SetInformationJobObject', 'int32_t', ['void *', 'int32_t', 'void *', 'uint32_t']);
// SetInformationJobObject(hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength)
// hJob : HANDLE -> 'void *'
// JobObjectInformationClass : JOBOBJECTINFOCLASS -> 'int32_t'
// lpJobObjectInformation : void* -> 'void *'
// cbJobObjectInformationLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  SetInformationJobObject: { parameters: ["pointer", "i32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetInformationJobObject(hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength)
// hJob : HANDLE -> "pointer"
// JobObjectInformationClass : JOBOBJECTINFOCLASS -> "i32"
// lpJobObjectInformation : void* -> "pointer"
// cbJobObjectInformationLength : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetInformationJobObject(
    void* hJob,
    int32_t JobObjectInformationClass,
    void* lpJobObjectInformation,
    uint32_t cbJobObjectInformationLength);
C, "KERNEL32.dll");
// $ffi->SetInformationJobObject(hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength);
// hJob : HANDLE
// JobObjectInformationClass : JOBOBJECTINFOCLASS
// lpJobObjectInformation : void*
// cbJobObjectInformationLength : DWORD
// 構造体/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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    boolean SetInformationJobObject(
        Pointer hJob,   // HANDLE
        int JobObjectInformationClass,   // JOBOBJECTINFOCLASS
        Pointer lpJobObjectInformation,   // void*
        int cbJobObjectInformationLength   // DWORD
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun SetInformationJobObject = SetInformationJobObject(
    hJob : Void*,   # HANDLE
    JobObjectInformationClass : Int32,   # JOBOBJECTINFOCLASS
    lpJobObjectInformation : Void*,   # void*
    cbJobObjectInformationLength : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetInformationJobObjectNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Uint32);
typedef SetInformationJobObjectDart = int Function(Pointer<Void>, int, Pointer<Void>, int);
final SetInformationJobObject = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<SetInformationJobObjectNative, SetInformationJobObjectDart>('SetInformationJobObject');
// hJob : HANDLE -> Pointer<Void>
// JobObjectInformationClass : JOBOBJECTINFOCLASS -> Int32
// lpJobObjectInformation : void* -> Pointer<Void>
// cbJobObjectInformationLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetInformationJobObject(
  hJob: THandle;   // HANDLE
  JobObjectInformationClass: Integer;   // JOBOBJECTINFOCLASS
  lpJobObjectInformation: Pointer;   // void*
  cbJobObjectInformationLength: DWORD   // DWORD
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetInformationJobObject';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetInformationJobObject"
  c_SetInformationJobObject :: Ptr () -> Int32 -> Ptr () -> Word32 -> IO CInt
-- hJob : HANDLE -> Ptr ()
-- JobObjectInformationClass : JOBOBJECTINFOCLASS -> Int32
-- lpJobObjectInformation : void* -> Ptr ()
-- cbJobObjectInformationLength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setinformationjobobject =
  foreign "SetInformationJobObject"
    ((ptr void) @-> int32_t @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* hJob : HANDLE -> (ptr void) *)
(* JobObjectInformationClass : JOBOBJECTINFOCLASS -> int32_t *)
(* lpJobObjectInformation : void* -> (ptr void) *)
(* cbJobObjectInformationLength : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("SetInformationJobObject" set-information-job-object :convention :stdcall) :int32
  (h-job :pointer)   ; HANDLE
  (job-object-information-class :int32)   ; JOBOBJECTINFOCLASS
  (lp-job-object-information :pointer)   ; void*
  (cb-job-object-information-length :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetInformationJobObject = Win32::API::More->new('KERNEL32',
    'BOOL SetInformationJobObject(HANDLE hJob, int JobObjectInformationClass, LPVOID lpJobObjectInformation, DWORD cbJobObjectInformationLength)');
# my $ret = $SetInformationJobObject->Call($hJob, $JobObjectInformationClass, $lpJobObjectInformation, $cbJobObjectInformationLength);
# hJob : HANDLE -> HANDLE
# JobObjectInformationClass : JOBOBJECTINFOCLASS -> int
# lpJobObjectInformation : void* -> LPVOID
# cbJobObjectInformationLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型