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

TrySubmitThreadpoolCallback

関数
簡易コールバックをスレッドプールに要求する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL TrySubmitThreadpoolCallback(
    PTP_SIMPLE_CALLBACK pfns,
    void* pv,   // optional
    TP_CALLBACK_ENVIRON_V3* pcbe   // optional
);

パラメーター

名前方向
pfnsPTP_SIMPLE_CALLBACKin
pvvoid*inoutoptional
pcbeTP_CALLBACK_ENVIRON_V3*inoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

TrySubmitThreadpoolCallback = ctypes.windll.kernel32.TrySubmitThreadpoolCallback
TrySubmitThreadpoolCallback.restype = wintypes.BOOL
TrySubmitThreadpoolCallback.argtypes = [
    ctypes.c_void_p,  # pfns : PTP_SIMPLE_CALLBACK
    ctypes.POINTER(None),  # pv : void* optional, in/out
    ctypes.c_void_p,  # pcbe : TP_CALLBACK_ENVIRON_V3* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procTrySubmitThreadpoolCallback = kernel32.NewProc("TrySubmitThreadpoolCallback")
)

// pfns (PTP_SIMPLE_CALLBACK), pv (void* optional, in/out), pcbe (TP_CALLBACK_ENVIRON_V3* optional)
r1, _, err := procTrySubmitThreadpoolCallback.Call(
	uintptr(pfns),
	uintptr(pv),
	uintptr(pcbe),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function TrySubmitThreadpoolCallback(
  pfns: Pointer;   // PTP_SIMPLE_CALLBACK
  pv: Pointer;   // void* optional, in/out
  pcbe: Pointer   // TP_CALLBACK_ENVIRON_V3* optional
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'TrySubmitThreadpoolCallback';
result := DllCall("KERNEL32\TrySubmitThreadpoolCallback"
    , "Ptr", pfns   ; PTP_SIMPLE_CALLBACK
    , "Ptr", pv   ; void* optional, in/out
    , "Ptr", pcbe   ; TP_CALLBACK_ENVIRON_V3* optional
    , "Int")   ; return: BOOL
●TrySubmitThreadpoolCallback(pfns, pv, pcbe) = DLL("KERNEL32.dll", "bool TrySubmitThreadpoolCallback(void*, void*, void*)")
# 呼び出し: TrySubmitThreadpoolCallback(pfns, pv, pcbe)
# pfns : PTP_SIMPLE_CALLBACK -> "void*"
# pv : void* optional, in/out -> "void*"
# pcbe : TP_CALLBACK_ENVIRON_V3* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。