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

TlsGetValue

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

シグネチャ

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

void* TlsGetValue(
    DWORD dwTlsIndex
);

パラメーター

名前方向
dwTlsIndexDWORDin

戻り値の型: void*

各言語での呼び出し定義

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

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

TlsGetValue = ctypes.windll.kernel32.TlsGetValue
TlsGetValue.restype = ctypes.c_void_p
TlsGetValue.argtypes = [
    wintypes.DWORD,  # dwTlsIndex : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
TlsGetValue = Fiddle::Function.new(
  lib['TlsGetValue'],
  [
    -Fiddle::TYPE_INT,  # dwTlsIndex : DWORD
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "kernel32")]
extern "system" {
    fn TlsGetValue(
        dwTlsIndex: u32  // DWORD
    ) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern IntPtr TlsGetValue(uint dwTlsIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_TlsGetValue' -Namespace Win32 -PassThru
# $api::TlsGetValue(dwTlsIndex)
#uselib "KERNEL32.dll"
#func global TlsGetValue "TlsGetValue" sptr
; TlsGetValue dwTlsIndex   ; 戻り値は stat
; dwTlsIndex : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global TlsGetValue "TlsGetValue" int
; res = TlsGetValue(dwTlsIndex)
; dwTlsIndex : DWORD -> "int"
; void* TlsGetValue(DWORD dwTlsIndex)
#uselib "KERNEL32.dll"
#cfunc global TlsGetValue "TlsGetValue" int
; res = TlsGetValue(dwTlsIndex)
; dwTlsIndex : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procTlsGetValue = kernel32.NewProc("TlsGetValue")
)

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