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

SetThreadpoolStackInformation

関数
スレッドプールのスタックサイズ情報を設定する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows 7 以降

シグネチャ

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

BOOL SetThreadpoolStackInformation(
    PTP_POOL ptpp,
    TP_POOL_STACK_INFORMATION* ptpsi
);

パラメーター

名前方向説明
ptppPTP_POOLinスレッドプールを指定する TP_POOL 構造体へのポインターです。このポインターは CreateThreadpool 関数によって返されます。
ptpsiTP_POOL_STACK_INFORMATION*inプール内のスレッドに対するスタックの予約サイズおよびコミットサイズを指定する TP_POOL_STACK_INFORMATION 構造体へのポインターです。

戻り値の型: BOOL

公式ドキュメント

指定したスレッドプール内の新しいスレッドに対して、スタックの予約サイズおよびコミットサイズを設定します。既存のスレッドのスタック予約サイズおよびコミットサイズは変更されません。

戻り値

関数が成功した場合、戻り値は 0 以外の値になります。

関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、 GetLastError を呼び出します。

解説(Remarks)

この関数を使用するアプリケーションをコンパイルするには、_WIN32_WINNT を _WIN32_WINNT_WIN7 に設定します。詳細については、Using the Windows Headers を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL SetThreadpoolStackInformation(
    PTP_POOL ptpp,
    TP_POOL_STACK_INFORMATION* ptpsi
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetThreadpoolStackInformation(
    IntPtr ptpp,   // PTP_POOL
    IntPtr ptpsi   // TP_POOL_STACK_INFORMATION*
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetThreadpoolStackInformation(
    ptpp As IntPtr,   ' PTP_POOL
    ptpsi As IntPtr   ' TP_POOL_STACK_INFORMATION*
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' ptpp : PTP_POOL
' ptpsi : TP_POOL_STACK_INFORMATION*
Declare PtrSafe Function SetThreadpoolStackInformation Lib "kernel32" ( _
    ByVal ptpp As LongPtr, _
    ByVal ptpsi As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetThreadpoolStackInformation = ctypes.windll.kernel32.SetThreadpoolStackInformation
SetThreadpoolStackInformation.restype = wintypes.BOOL
SetThreadpoolStackInformation.argtypes = [
    ctypes.c_ssize_t,  # ptpp : PTP_POOL
    ctypes.c_void_p,  # ptpsi : TP_POOL_STACK_INFORMATION*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetThreadpoolStackInformation = Fiddle::Function.new(
  lib['SetThreadpoolStackInformation'],
  [
    Fiddle::TYPE_INTPTR_T,  # ptpp : PTP_POOL
    Fiddle::TYPE_VOIDP,  # ptpsi : TP_POOL_STACK_INFORMATION*
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SetThreadpoolStackInformation(
        ptpp: isize,  // PTP_POOL
        ptpsi: *mut TP_POOL_STACK_INFORMATION  // TP_POOL_STACK_INFORMATION*
    ) -> 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 SetThreadpoolStackInformation(IntPtr ptpp, IntPtr ptpsi);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetThreadpoolStackInformation' -Namespace Win32 -PassThru
# $api::SetThreadpoolStackInformation(ptpp, ptpsi)
#uselib "KERNEL32.dll"
#func global SetThreadpoolStackInformation "SetThreadpoolStackInformation" sptr, sptr
; SetThreadpoolStackInformation ptpp, varptr(ptpsi)   ; 戻り値は stat
; ptpp : PTP_POOL -> "sptr"
; ptpsi : TP_POOL_STACK_INFORMATION* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global SetThreadpoolStackInformation "SetThreadpoolStackInformation" sptr, var
; res = SetThreadpoolStackInformation(ptpp, ptpsi)
; ptpp : PTP_POOL -> "sptr"
; ptpsi : TP_POOL_STACK_INFORMATION* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetThreadpoolStackInformation(PTP_POOL ptpp, TP_POOL_STACK_INFORMATION* ptpsi)
#uselib "KERNEL32.dll"
#cfunc global SetThreadpoolStackInformation "SetThreadpoolStackInformation" intptr, var
; res = SetThreadpoolStackInformation(ptpp, ptpsi)
; ptpp : PTP_POOL -> "intptr"
; ptpsi : TP_POOL_STACK_INFORMATION* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetThreadpoolStackInformation = kernel32.NewProc("SetThreadpoolStackInformation")
)

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

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

typedef SetThreadpoolStackInformationNative = Int32 Function(IntPtr, Pointer<Void>);
typedef SetThreadpoolStackInformationDart = int Function(int, Pointer<Void>);
final SetThreadpoolStackInformation = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<SetThreadpoolStackInformationNative, SetThreadpoolStackInformationDart>('SetThreadpoolStackInformation');
// ptpp : PTP_POOL -> IntPtr
// ptpsi : TP_POOL_STACK_INFORMATION* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetThreadpoolStackInformation(
  ptpp: NativeInt;   // PTP_POOL
  ptpsi: Pointer   // TP_POOL_STACK_INFORMATION*
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetThreadpoolStackInformation';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetThreadpoolStackInformation"
  c_SetThreadpoolStackInformation :: CIntPtr -> Ptr () -> IO CInt
-- ptpp : PTP_POOL -> CIntPtr
-- ptpsi : TP_POOL_STACK_INFORMATION* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setthreadpoolstackinformation =
  foreign "SetThreadpoolStackInformation"
    (intptr_t @-> (ptr void) @-> returning int32_t)
(* ptpp : PTP_POOL -> intptr_t *)
(* ptpsi : TP_POOL_STACK_INFORMATION* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("SetThreadpoolStackInformation" set-threadpool-stack-information :convention :stdcall) :int32
  (ptpp :int64)   ; PTP_POOL
  (ptpsi :pointer))   ; TP_POOL_STACK_INFORMATION*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetThreadpoolStackInformation = Win32::API::More->new('KERNEL32',
    'BOOL SetThreadpoolStackInformation(LPARAM ptpp, LPVOID ptpsi)');
# my $ret = $SetThreadpoolStackInformation->Call($ptpp, $ptpsi);
# ptpp : PTP_POOL -> LPARAM
# ptpsi : TP_POOL_STACK_INFORMATION* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型