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

QueryInformationJobObject

関数
ジョブオブジェクトの情報を照会する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL QueryInformationJobObject(
    HANDLE hJob,   // optional
    JOBOBJECTINFOCLASS JobObjectInformationClass,
    void* lpJobObjectInformation,
    DWORD cbJobObjectInformationLength,
    DWORD* lpReturnLength   // optional
);

パラメーター

名前方向説明
hJobHANDLEinoptional情報を取得する対象ジョブのハンドル。JOB_OBJECT_QUERY権限が必要。NULL可(呼び出し元のジョブを参照)。
JobObjectInformationClassJOBOBJECTINFOCLASSin取得する情報の種類を示す列挙値。受け取る構造体の型を決める。
lpJobObjectInformationvoid*out取得した情報を受け取るバッファへのポインタ。クラスに対応した構造体を指す。
cbJobObjectInformationLengthDWORDinlpJobObjectInformationが指すバッファのサイズ(バイト単位)。
lpReturnLengthDWORD*outoptional実際に書き込まれたバイト数を受け取る変数へのポインタ。NULL可。

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

lib = Fiddle.dlopen('KERNEL32.dll')
QueryInformationJobObject = Fiddle::Function.new(
  lib['QueryInformationJobObject'],
  [
    Fiddle::TYPE_VOIDP,  # hJob : HANDLE optional
    Fiddle::TYPE_INT,  # JobObjectInformationClass : JOBOBJECTINFOCLASS
    Fiddle::TYPE_VOIDP,  # lpJobObjectInformation : void* out
    -Fiddle::TYPE_INT,  # cbJobObjectInformationLength : DWORD
    Fiddle::TYPE_VOIDP,  # lpReturnLength : DWORD* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn QueryInformationJobObject(
        hJob: *mut core::ffi::c_void,  // HANDLE optional
        JobObjectInformationClass: i32,  // JOBOBJECTINFOCLASS
        lpJobObjectInformation: *mut (),  // void* out
        cbJobObjectInformationLength: u32,  // DWORD
        lpReturnLength: *mut u32  // DWORD* optional, out
    ) -> 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 QueryInformationJobObject(IntPtr hJob, int JobObjectInformationClass, IntPtr lpJobObjectInformation, uint cbJobObjectInformationLength, IntPtr lpReturnLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_QueryInformationJobObject' -Namespace Win32 -PassThru
# $api::QueryInformationJobObject(hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength, lpReturnLength)
#uselib "KERNEL32.dll"
#func global QueryInformationJobObject "QueryInformationJobObject" sptr, sptr, sptr, sptr, sptr
; QueryInformationJobObject hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength, varptr(lpReturnLength)   ; 戻り値は stat
; hJob : HANDLE optional -> "sptr"
; JobObjectInformationClass : JOBOBJECTINFOCLASS -> "sptr"
; lpJobObjectInformation : void* out -> "sptr"
; cbJobObjectInformationLength : DWORD -> "sptr"
; lpReturnLength : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global QueryInformationJobObject "QueryInformationJobObject" sptr, int, sptr, int, var
; res = QueryInformationJobObject(hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength, lpReturnLength)
; hJob : HANDLE optional -> "sptr"
; JobObjectInformationClass : JOBOBJECTINFOCLASS -> "int"
; lpJobObjectInformation : void* out -> "sptr"
; cbJobObjectInformationLength : DWORD -> "int"
; lpReturnLength : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL QueryInformationJobObject(HANDLE hJob, JOBOBJECTINFOCLASS JobObjectInformationClass, void* lpJobObjectInformation, DWORD cbJobObjectInformationLength, DWORD* lpReturnLength)
#uselib "KERNEL32.dll"
#cfunc global QueryInformationJobObject "QueryInformationJobObject" intptr, int, intptr, int, var
; res = QueryInformationJobObject(hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength, lpReturnLength)
; hJob : HANDLE optional -> "intptr"
; JobObjectInformationClass : JOBOBJECTINFOCLASS -> "int"
; lpJobObjectInformation : void* out -> "intptr"
; cbJobObjectInformationLength : DWORD -> "int"
; lpReturnLength : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procQueryInformationJobObject = kernel32.NewProc("QueryInformationJobObject")
)

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

extern "kernel32" fn QueryInformationJobObject(
    hJob: ?*anyopaque, // HANDLE optional
    JobObjectInformationClass: i32, // JOBOBJECTINFOCLASS
    lpJobObjectInformation: ?*anyopaque, // void* out
    cbJobObjectInformationLength: u32, // DWORD
    lpReturnLength: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc QueryInformationJobObject(
    hJob: pointer,  # HANDLE optional
    JobObjectInformationClass: int32,  # JOBOBJECTINFOCLASS
    lpJobObjectInformation: pointer,  # void* out
    cbJobObjectInformationLength: uint32,  # DWORD
    lpReturnLength: ptr uint32  # DWORD* optional, out
): int32 {.importc: "QueryInformationJobObject", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int QueryInformationJobObject(
    void* hJob,   // HANDLE optional
    int JobObjectInformationClass,   // JOBOBJECTINFOCLASS
    void* lpJobObjectInformation,   // void* out
    uint cbJobObjectInformationLength,   // DWORD
    uint* lpReturnLength   // DWORD* optional, out
);
ccall((:QueryInformationJobObject, "KERNEL32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
      hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength, lpReturnLength)
# hJob : HANDLE optional -> Ptr{Cvoid}
# JobObjectInformationClass : JOBOBJECTINFOCLASS -> Int32
# lpJobObjectInformation : void* out -> Ptr{Cvoid}
# cbJobObjectInformationLength : DWORD -> UInt32
# lpReturnLength : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t QueryInformationJobObject(
    void* hJob,
    int32_t JobObjectInformationClass,
    void* lpJobObjectInformation,
    uint32_t cbJobObjectInformationLength,
    uint32_t* lpReturnLength);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.QueryInformationJobObject(hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength, lpReturnLength)
-- hJob : HANDLE optional
-- JobObjectInformationClass : JOBOBJECTINFOCLASS
-- lpJobObjectInformation : void* out
-- cbJobObjectInformationLength : DWORD
-- lpReturnLength : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const QueryInformationJobObject = lib.func('__stdcall', 'QueryInformationJobObject', 'int32_t', ['void *', 'int32_t', 'void *', 'uint32_t', 'uint32_t *']);
// QueryInformationJobObject(hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength, lpReturnLength)
// hJob : HANDLE optional -> 'void *'
// JobObjectInformationClass : JOBOBJECTINFOCLASS -> 'int32_t'
// lpJobObjectInformation : void* out -> 'void *'
// cbJobObjectInformationLength : DWORD -> 'uint32_t'
// lpReturnLength : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  QueryInformationJobObject: { parameters: ["pointer", "i32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.QueryInformationJobObject(hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength, lpReturnLength)
// hJob : HANDLE optional -> "pointer"
// JobObjectInformationClass : JOBOBJECTINFOCLASS -> "i32"
// lpJobObjectInformation : void* out -> "pointer"
// cbJobObjectInformationLength : DWORD -> "u32"
// lpReturnLength : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t QueryInformationJobObject(
    void* hJob,
    int32_t JobObjectInformationClass,
    void* lpJobObjectInformation,
    uint32_t cbJobObjectInformationLength,
    uint32_t* lpReturnLength);
C, "KERNEL32.dll");
// $ffi->QueryInformationJobObject(hJob, JobObjectInformationClass, lpJobObjectInformation, cbJobObjectInformationLength, lpReturnLength);
// hJob : HANDLE optional
// JobObjectInformationClass : JOBOBJECTINFOCLASS
// lpJobObjectInformation : void* out
// cbJobObjectInformationLength : DWORD
// lpReturnLength : 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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    boolean QueryInformationJobObject(
        Pointer hJob,   // HANDLE optional
        int JobObjectInformationClass,   // JOBOBJECTINFOCLASS
        Pointer lpJobObjectInformation,   // void* out
        int cbJobObjectInformationLength,   // DWORD
        IntByReference lpReturnLength   // DWORD* optional, out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun QueryInformationJobObject = QueryInformationJobObject(
    hJob : Void*,   # HANDLE optional
    JobObjectInformationClass : Int32,   # JOBOBJECTINFOCLASS
    lpJobObjectInformation : Void*,   # void* out
    cbJobObjectInformationLength : UInt32,   # DWORD
    lpReturnLength : 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 QueryInformationJobObjectNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef QueryInformationJobObjectDart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Uint32>);
final QueryInformationJobObject = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<QueryInformationJobObjectNative, QueryInformationJobObjectDart>('QueryInformationJobObject');
// hJob : HANDLE optional -> Pointer<Void>
// JobObjectInformationClass : JOBOBJECTINFOCLASS -> Int32
// lpJobObjectInformation : void* out -> Pointer<Void>
// cbJobObjectInformationLength : DWORD -> Uint32
// lpReturnLength : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function QueryInformationJobObject(
  hJob: THandle;   // HANDLE optional
  JobObjectInformationClass: Integer;   // JOBOBJECTINFOCLASS
  lpJobObjectInformation: Pointer;   // void* out
  cbJobObjectInformationLength: DWORD;   // DWORD
  lpReturnLength: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'QueryInformationJobObject';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

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

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

関連項目

使用する型