ホーム › System.SystemInformation › GetSystemCpuSetInformation
GetSystemCpuSetInformation
関数システムのCPUセット情報を取得する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL GetSystemCpuSetInformation(
SYSTEM_CPU_SET_INFORMATION* Information, // optional
DWORD BufferLength,
DWORD* ReturnedLength,
HANDLE Process, // optional
DWORD Flags // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Information | SYSTEM_CPU_SET_INFORMATION* | outoptional | CPU セット情報の配列を受け取るバッファ。NULL でサイズ照会。 |
| BufferLength | DWORD | in | Information バッファのサイズ(バイト単位)。 |
| ReturnedLength | DWORD* | out | 必要/返却バイト数を受け取るポインタ。 |
| Process | HANDLE | inoptional | 対象プロセスのハンドル。NULL で呼び出しプロセス。 |
| Flags | DWORD | optional | 予約済みで 0 を指定する。 |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL GetSystemCpuSetInformation(
SYSTEM_CPU_SET_INFORMATION* Information, // optional
DWORD BufferLength,
DWORD* ReturnedLength,
HANDLE Process, // optional
DWORD Flags // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool GetSystemCpuSetInformation(
IntPtr Information, // SYSTEM_CPU_SET_INFORMATION* optional, out
uint BufferLength, // DWORD
out uint ReturnedLength, // DWORD* out
IntPtr Process, // HANDLE optional
uint Flags // DWORD optional
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function GetSystemCpuSetInformation(
Information As IntPtr, ' SYSTEM_CPU_SET_INFORMATION* optional, out
BufferLength As UInteger, ' DWORD
<Out> ByRef ReturnedLength As UInteger, ' DWORD* out
Process As IntPtr, ' HANDLE optional
Flags As UInteger ' DWORD optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' Information : SYSTEM_CPU_SET_INFORMATION* optional, out
' BufferLength : DWORD
' ReturnedLength : DWORD* out
' Process : HANDLE optional
' Flags : DWORD optional
Declare PtrSafe Function GetSystemCpuSetInformation Lib "kernel32" ( _
ByVal Information As LongPtr, _
ByVal BufferLength As Long, _
ByRef ReturnedLength As Long, _
ByVal Process As LongPtr, _
ByVal Flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetSystemCpuSetInformation = ctypes.windll.kernel32.GetSystemCpuSetInformation
GetSystemCpuSetInformation.restype = wintypes.BOOL
GetSystemCpuSetInformation.argtypes = [
ctypes.c_void_p, # Information : SYSTEM_CPU_SET_INFORMATION* optional, out
wintypes.DWORD, # BufferLength : DWORD
ctypes.POINTER(wintypes.DWORD), # ReturnedLength : DWORD* out
wintypes.HANDLE, # Process : HANDLE optional
wintypes.DWORD, # Flags : DWORD optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetSystemCpuSetInformation = Fiddle::Function.new(
lib['GetSystemCpuSetInformation'],
[
Fiddle::TYPE_VOIDP, # Information : SYSTEM_CPU_SET_INFORMATION* optional, out
-Fiddle::TYPE_INT, # BufferLength : DWORD
Fiddle::TYPE_VOIDP, # ReturnedLength : DWORD* out
Fiddle::TYPE_VOIDP, # Process : HANDLE optional
-Fiddle::TYPE_INT, # Flags : DWORD optional
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn GetSystemCpuSetInformation(
Information: *mut SYSTEM_CPU_SET_INFORMATION, // SYSTEM_CPU_SET_INFORMATION* optional, out
BufferLength: u32, // DWORD
ReturnedLength: *mut u32, // DWORD* out
Process: *mut core::ffi::c_void, // HANDLE optional
Flags: u32 // DWORD optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll")]
public static extern bool GetSystemCpuSetInformation(IntPtr Information, uint BufferLength, out uint ReturnedLength, IntPtr Process, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetSystemCpuSetInformation' -Namespace Win32 -PassThru
# $api::GetSystemCpuSetInformation(Information, BufferLength, ReturnedLength, Process, Flags)#uselib "KERNEL32.dll"
#func global GetSystemCpuSetInformation "GetSystemCpuSetInformation" sptr, sptr, sptr, sptr, sptr
; GetSystemCpuSetInformation varptr(Information), BufferLength, varptr(ReturnedLength), Process, Flags ; 戻り値は stat
; Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> "sptr"
; BufferLength : DWORD -> "sptr"
; ReturnedLength : DWORD* out -> "sptr"
; Process : HANDLE optional -> "sptr"
; Flags : DWORD optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global GetSystemCpuSetInformation "GetSystemCpuSetInformation" var, int, var, sptr, int ; res = GetSystemCpuSetInformation(Information, BufferLength, ReturnedLength, Process, Flags) ; Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> "var" ; BufferLength : DWORD -> "int" ; ReturnedLength : DWORD* out -> "var" ; Process : HANDLE optional -> "sptr" ; Flags : DWORD optional -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetSystemCpuSetInformation "GetSystemCpuSetInformation" sptr, int, sptr, sptr, int ; res = GetSystemCpuSetInformation(varptr(Information), BufferLength, varptr(ReturnedLength), Process, Flags) ; Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> "sptr" ; BufferLength : DWORD -> "int" ; ReturnedLength : DWORD* out -> "sptr" ; Process : HANDLE optional -> "sptr" ; Flags : DWORD optional -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetSystemCpuSetInformation(SYSTEM_CPU_SET_INFORMATION* Information, DWORD BufferLength, DWORD* ReturnedLength, HANDLE Process, DWORD Flags) #uselib "KERNEL32.dll" #cfunc global GetSystemCpuSetInformation "GetSystemCpuSetInformation" var, int, var, intptr, int ; res = GetSystemCpuSetInformation(Information, BufferLength, ReturnedLength, Process, Flags) ; Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> "var" ; BufferLength : DWORD -> "int" ; ReturnedLength : DWORD* out -> "var" ; Process : HANDLE optional -> "intptr" ; Flags : DWORD optional -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetSystemCpuSetInformation(SYSTEM_CPU_SET_INFORMATION* Information, DWORD BufferLength, DWORD* ReturnedLength, HANDLE Process, DWORD Flags) #uselib "KERNEL32.dll" #cfunc global GetSystemCpuSetInformation "GetSystemCpuSetInformation" intptr, int, intptr, intptr, int ; res = GetSystemCpuSetInformation(varptr(Information), BufferLength, varptr(ReturnedLength), Process, Flags) ; Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> "intptr" ; BufferLength : DWORD -> "int" ; ReturnedLength : DWORD* out -> "intptr" ; Process : HANDLE optional -> "intptr" ; Flags : DWORD optional -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetSystemCpuSetInformation = kernel32.NewProc("GetSystemCpuSetInformation")
)
// Information (SYSTEM_CPU_SET_INFORMATION* optional, out), BufferLength (DWORD), ReturnedLength (DWORD* out), Process (HANDLE optional), Flags (DWORD optional)
r1, _, err := procGetSystemCpuSetInformation.Call(
uintptr(Information),
uintptr(BufferLength),
uintptr(ReturnedLength),
uintptr(Process),
uintptr(Flags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetSystemCpuSetInformation(
Information: Pointer; // SYSTEM_CPU_SET_INFORMATION* optional, out
BufferLength: DWORD; // DWORD
ReturnedLength: Pointer; // DWORD* out
Process: THandle; // HANDLE optional
Flags: DWORD // DWORD optional
): BOOL; stdcall;
external 'KERNEL32.dll' name 'GetSystemCpuSetInformation';result := DllCall("KERNEL32\GetSystemCpuSetInformation"
, "Ptr", Information ; SYSTEM_CPU_SET_INFORMATION* optional, out
, "UInt", BufferLength ; DWORD
, "Ptr", ReturnedLength ; DWORD* out
, "Ptr", Process ; HANDLE optional
, "UInt", Flags ; DWORD optional
, "Int") ; return: BOOL●GetSystemCpuSetInformation(Information, BufferLength, ReturnedLength, Process, Flags) = DLL("KERNEL32.dll", "bool GetSystemCpuSetInformation(void*, dword, void*, void*, dword)")
# 呼び出し: GetSystemCpuSetInformation(Information, BufferLength, ReturnedLength, Process, Flags)
# Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> "void*"
# BufferLength : DWORD -> "dword"
# ReturnedLength : DWORD* out -> "void*"
# Process : HANDLE optional -> "void*"
# Flags : DWORD optional -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn GetSystemCpuSetInformation(
Information: [*c]SYSTEM_CPU_SET_INFORMATION, // SYSTEM_CPU_SET_INFORMATION* optional, out
BufferLength: u32, // DWORD
ReturnedLength: [*c]u32, // DWORD* out
Process: ?*anyopaque, // HANDLE optional
Flags: u32 // DWORD optional
) callconv(std.os.windows.WINAPI) i32;proc GetSystemCpuSetInformation(
Information: ptr SYSTEM_CPU_SET_INFORMATION, # SYSTEM_CPU_SET_INFORMATION* optional, out
BufferLength: uint32, # DWORD
ReturnedLength: ptr uint32, # DWORD* out
Process: pointer, # HANDLE optional
Flags: uint32 # DWORD optional
): int32 {.importc: "GetSystemCpuSetInformation", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int GetSystemCpuSetInformation(
SYSTEM_CPU_SET_INFORMATION* Information, // SYSTEM_CPU_SET_INFORMATION* optional, out
uint BufferLength, // DWORD
uint* ReturnedLength, // DWORD* out
void* Process, // HANDLE optional
uint Flags // DWORD optional
);ccall((:GetSystemCpuSetInformation, "KERNEL32.dll"), stdcall, Int32,
(Ptr{SYSTEM_CPU_SET_INFORMATION}, UInt32, Ptr{UInt32}, Ptr{Cvoid}, UInt32),
Information, BufferLength, ReturnedLength, Process, Flags)
# Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> Ptr{SYSTEM_CPU_SET_INFORMATION}
# BufferLength : DWORD -> UInt32
# ReturnedLength : DWORD* out -> Ptr{UInt32}
# Process : HANDLE optional -> Ptr{Cvoid}
# Flags : DWORD optional -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetSystemCpuSetInformation(
void* Information,
uint32_t BufferLength,
uint32_t* ReturnedLength,
void* Process,
uint32_t Flags);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetSystemCpuSetInformation(Information, BufferLength, ReturnedLength, Process, Flags)
-- Information : SYSTEM_CPU_SET_INFORMATION* optional, out
-- BufferLength : DWORD
-- ReturnedLength : DWORD* out
-- Process : HANDLE optional
-- Flags : DWORD optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetSystemCpuSetInformation = lib.func('__stdcall', 'GetSystemCpuSetInformation', 'int32_t', ['void *', 'uint32_t', 'uint32_t *', 'void *', 'uint32_t']);
// GetSystemCpuSetInformation(Information, BufferLength, ReturnedLength, Process, Flags)
// Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> 'void *'
// BufferLength : DWORD -> 'uint32_t'
// ReturnedLength : DWORD* out -> 'uint32_t *'
// Process : HANDLE optional -> 'void *'
// Flags : DWORD optional -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
GetSystemCpuSetInformation: { parameters: ["pointer", "u32", "pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.GetSystemCpuSetInformation(Information, BufferLength, ReturnedLength, Process, Flags)
// Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> "pointer"
// BufferLength : DWORD -> "u32"
// ReturnedLength : DWORD* out -> "pointer"
// Process : HANDLE optional -> "pointer"
// Flags : DWORD optional -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetSystemCpuSetInformation(
void* Information,
uint32_t BufferLength,
uint32_t* ReturnedLength,
void* Process,
uint32_t Flags);
C, "KERNEL32.dll");
// $ffi->GetSystemCpuSetInformation(Information, BufferLength, ReturnedLength, Process, Flags);
// Information : SYSTEM_CPU_SET_INFORMATION* optional, out
// BufferLength : DWORD
// ReturnedLength : DWORD* out
// Process : HANDLE optional
// Flags : DWORD optional
// 構造体/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 GetSystemCpuSetInformation(
Pointer Information, // SYSTEM_CPU_SET_INFORMATION* optional, out
int BufferLength, // DWORD
IntByReference ReturnedLength, // DWORD* out
Pointer Process, // HANDLE optional
int Flags // DWORD optional
);
}@[Link("kernel32")]
lib LibKERNEL32
fun GetSystemCpuSetInformation = GetSystemCpuSetInformation(
Information : SYSTEM_CPU_SET_INFORMATION*, # SYSTEM_CPU_SET_INFORMATION* optional, out
BufferLength : UInt32, # DWORD
ReturnedLength : UInt32*, # DWORD* out
Process : Void*, # HANDLE optional
Flags : UInt32 # DWORD optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetSystemCpuSetInformationNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Uint32>, Pointer<Void>, Uint32);
typedef GetSystemCpuSetInformationDart = int Function(Pointer<Void>, int, Pointer<Uint32>, Pointer<Void>, int);
final GetSystemCpuSetInformation = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<GetSystemCpuSetInformationNative, GetSystemCpuSetInformationDart>('GetSystemCpuSetInformation');
// Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> Pointer<Void>
// BufferLength : DWORD -> Uint32
// ReturnedLength : DWORD* out -> Pointer<Uint32>
// Process : HANDLE optional -> Pointer<Void>
// Flags : DWORD optional -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetSystemCpuSetInformation(
Information: Pointer; // SYSTEM_CPU_SET_INFORMATION* optional, out
BufferLength: DWORD; // DWORD
ReturnedLength: Pointer; // DWORD* out
Process: THandle; // HANDLE optional
Flags: DWORD // DWORD optional
): BOOL; stdcall;
external 'KERNEL32.dll' name 'GetSystemCpuSetInformation';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetSystemCpuSetInformation"
c_GetSystemCpuSetInformation :: Ptr () -> Word32 -> Ptr Word32 -> Ptr () -> Word32 -> IO CInt
-- Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> Ptr ()
-- BufferLength : DWORD -> Word32
-- ReturnedLength : DWORD* out -> Ptr Word32
-- Process : HANDLE optional -> Ptr ()
-- Flags : DWORD optional -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getsystemcpusetinformation =
foreign "GetSystemCpuSetInformation"
((ptr void) @-> uint32_t @-> (ptr uint32_t) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> (ptr void) *)
(* BufferLength : DWORD -> uint32_t *)
(* ReturnedLength : DWORD* out -> (ptr uint32_t) *)
(* Process : HANDLE optional -> (ptr void) *)
(* Flags : DWORD optional -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("GetSystemCpuSetInformation" get-system-cpu-set-information :convention :stdcall) :int32
(information :pointer) ; SYSTEM_CPU_SET_INFORMATION* optional, out
(buffer-length :uint32) ; DWORD
(returned-length :pointer) ; DWORD* out
(process :pointer) ; HANDLE optional
(flags :uint32)) ; DWORD optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetSystemCpuSetInformation = Win32::API::More->new('KERNEL32',
'BOOL GetSystemCpuSetInformation(LPVOID Information, DWORD BufferLength, LPVOID ReturnedLength, HANDLE Process, DWORD Flags)');
# my $ret = $GetSystemCpuSetInformation->Call($Information, $BufferLength, $ReturnedLength, $Process, $Flags);
# Information : SYSTEM_CPU_SET_INFORMATION* optional, out -> LPVOID
# BufferLength : DWORD -> DWORD
# ReturnedLength : DWORD* out -> LPVOID
# Process : HANDLE optional -> HANDLE
# Flags : DWORD optional -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。