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

TlsGetValue2

関数
指定TLSスロットの値を取得する(最終エラー保持版)。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

void* TlsGetValue2(
    DWORD dwTlsIndex
);

パラメーター

名前方向
dwTlsIndexDWORDin

戻り値の型: void*

各言語での呼び出し定義

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

void* TlsGetValue2(
    DWORD dwTlsIndex
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern IntPtr TlsGetValue2(
    uint dwTlsIndex   // DWORD
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function TlsGetValue2(
    dwTlsIndex As UInteger   ' DWORD
) As IntPtr
End Function
' dwTlsIndex : DWORD
Declare PtrSafe Function TlsGetValue2 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

TlsGetValue2 = ctypes.windll.kernel32.TlsGetValue2
TlsGetValue2.restype = ctypes.c_void_p
TlsGetValue2.argtypes = [
    wintypes.DWORD,  # dwTlsIndex : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procTlsGetValue2 = kernel32.NewProc("TlsGetValue2")
)

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