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

TlsSetValue

関数
指定TLSスロットに値を格納する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL TlsSetValue(
    DWORD dwTlsIndex,
    void* lpTlsValue   // optional
);

パラメーター

名前方向
dwTlsIndexDWORDin
lpTlsValuevoid*inoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

TlsSetValue = ctypes.windll.kernel32.TlsSetValue
TlsSetValue.restype = wintypes.BOOL
TlsSetValue.argtypes = [
    wintypes.DWORD,  # dwTlsIndex : DWORD
    ctypes.POINTER(None),  # lpTlsValue : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procTlsSetValue = kernel32.NewProc("TlsSetValue")
)

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