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

Tbsip_Submit_Command

関数
TPMにコマンドを送信し、結果を受け取る。
DLLtbs.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD Tbsip_Submit_Command(
    void* hContext,
    TBS_COMMAND_LOCALITY Locality,
    TBS_COMMAND_PRIORITY Priority,
    BYTE* pabCommand,
    DWORD cbCommand,
    BYTE* pabResult,
    DWORD* pcbResult
);

パラメーター

名前方向説明
hContextvoid*inコマンドを送信する対象のTBSコンテキストハンドル(void*)。
LocalityTBS_COMMAND_LOCALITYinコマンドを発行するTPMのローカリティ(TBS_COMMAND_LOCALITY)。通常は0。
PriorityTBS_COMMAND_PRIORITYinコマンドの処理優先度(TBS_COMMAND_PRIORITY)。
pabCommandBYTE*inTPMへ送るコマンドバイト列のバッファへのポインタ。
cbCommandDWORDinコマンドバッファのサイズ(バイト単位)。
pabResultBYTE*outTPMからの応答を格納する出力バッファへのポインタ。
pcbResultDWORD*inout入力で応答バッファ容量、出力で実際の応答サイズを受け取る(DWORD*)。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD Tbsip_Submit_Command(
    void* hContext,
    TBS_COMMAND_LOCALITY Locality,
    TBS_COMMAND_PRIORITY Priority,
    BYTE* pabCommand,
    DWORD cbCommand,
    BYTE* pabResult,
    DWORD* pcbResult
);
[DllImport("tbs.dll", ExactSpelling = true)]
static extern uint Tbsip_Submit_Command(
    IntPtr hContext,   // void*
    uint Locality,   // TBS_COMMAND_LOCALITY
    uint Priority,   // TBS_COMMAND_PRIORITY
    IntPtr pabCommand,   // BYTE*
    uint cbCommand,   // DWORD
    IntPtr pabResult,   // BYTE* out
    ref uint pcbResult   // DWORD* in/out
);
<DllImport("tbs.dll", ExactSpelling:=True)>
Public Shared Function Tbsip_Submit_Command(
    hContext As IntPtr,   ' void*
    Locality As UInteger,   ' TBS_COMMAND_LOCALITY
    Priority As UInteger,   ' TBS_COMMAND_PRIORITY
    pabCommand As IntPtr,   ' BYTE*
    cbCommand As UInteger,   ' DWORD
    pabResult As IntPtr,   ' BYTE* out
    ByRef pcbResult As UInteger   ' DWORD* in/out
) As UInteger
End Function
' hContext : void*
' Locality : TBS_COMMAND_LOCALITY
' Priority : TBS_COMMAND_PRIORITY
' pabCommand : BYTE*
' cbCommand : DWORD
' pabResult : BYTE* out
' pcbResult : DWORD* in/out
Declare PtrSafe Function Tbsip_Submit_Command Lib "tbs" ( _
    ByVal hContext As LongPtr, _
    ByVal Locality As Long, _
    ByVal Priority As Long, _
    ByVal pabCommand As LongPtr, _
    ByVal cbCommand As Long, _
    ByVal pabResult As LongPtr, _
    ByRef pcbResult As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

Tbsip_Submit_Command = ctypes.windll.tbs.Tbsip_Submit_Command
Tbsip_Submit_Command.restype = wintypes.DWORD
Tbsip_Submit_Command.argtypes = [
    ctypes.POINTER(None),  # hContext : void*
    wintypes.DWORD,  # Locality : TBS_COMMAND_LOCALITY
    wintypes.DWORD,  # Priority : TBS_COMMAND_PRIORITY
    ctypes.POINTER(ctypes.c_ubyte),  # pabCommand : BYTE*
    wintypes.DWORD,  # cbCommand : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # pabResult : BYTE* out
    ctypes.POINTER(wintypes.DWORD),  # pcbResult : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('tbs.dll')
Tbsip_Submit_Command = Fiddle::Function.new(
  lib['Tbsip_Submit_Command'],
  [
    Fiddle::TYPE_VOIDP,  # hContext : void*
    -Fiddle::TYPE_INT,  # Locality : TBS_COMMAND_LOCALITY
    -Fiddle::TYPE_INT,  # Priority : TBS_COMMAND_PRIORITY
    Fiddle::TYPE_VOIDP,  # pabCommand : BYTE*
    -Fiddle::TYPE_INT,  # cbCommand : DWORD
    Fiddle::TYPE_VOIDP,  # pabResult : BYTE* out
    Fiddle::TYPE_VOIDP,  # pcbResult : DWORD* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "tbs")]
extern "system" {
    fn Tbsip_Submit_Command(
        hContext: *mut (),  // void*
        Locality: u32,  // TBS_COMMAND_LOCALITY
        Priority: u32,  // TBS_COMMAND_PRIORITY
        pabCommand: *mut u8,  // BYTE*
        cbCommand: u32,  // DWORD
        pabResult: *mut u8,  // BYTE* out
        pcbResult: *mut u32  // DWORD* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("tbs.dll")]
public static extern uint Tbsip_Submit_Command(IntPtr hContext, uint Locality, uint Priority, IntPtr pabCommand, uint cbCommand, IntPtr pabResult, ref uint pcbResult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'tbs_Tbsip_Submit_Command' -Namespace Win32 -PassThru
# $api::Tbsip_Submit_Command(hContext, Locality, Priority, pabCommand, cbCommand, pabResult, pcbResult)
#uselib "tbs.dll"
#func global Tbsip_Submit_Command "Tbsip_Submit_Command" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; Tbsip_Submit_Command hContext, Locality, Priority, varptr(pabCommand), cbCommand, varptr(pabResult), varptr(pcbResult)   ; 戻り値は stat
; hContext : void* -> "sptr"
; Locality : TBS_COMMAND_LOCALITY -> "sptr"
; Priority : TBS_COMMAND_PRIORITY -> "sptr"
; pabCommand : BYTE* -> "sptr"
; cbCommand : DWORD -> "sptr"
; pabResult : BYTE* out -> "sptr"
; pcbResult : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "tbs.dll"
#cfunc global Tbsip_Submit_Command "Tbsip_Submit_Command" sptr, int, int, var, int, var, var
; res = Tbsip_Submit_Command(hContext, Locality, Priority, pabCommand, cbCommand, pabResult, pcbResult)
; hContext : void* -> "sptr"
; Locality : TBS_COMMAND_LOCALITY -> "int"
; Priority : TBS_COMMAND_PRIORITY -> "int"
; pabCommand : BYTE* -> "var"
; cbCommand : DWORD -> "int"
; pabResult : BYTE* out -> "var"
; pcbResult : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD Tbsip_Submit_Command(void* hContext, TBS_COMMAND_LOCALITY Locality, TBS_COMMAND_PRIORITY Priority, BYTE* pabCommand, DWORD cbCommand, BYTE* pabResult, DWORD* pcbResult)
#uselib "tbs.dll"
#cfunc global Tbsip_Submit_Command "Tbsip_Submit_Command" intptr, int, int, var, int, var, var
; res = Tbsip_Submit_Command(hContext, Locality, Priority, pabCommand, cbCommand, pabResult, pcbResult)
; hContext : void* -> "intptr"
; Locality : TBS_COMMAND_LOCALITY -> "int"
; Priority : TBS_COMMAND_PRIORITY -> "int"
; pabCommand : BYTE* -> "var"
; cbCommand : DWORD -> "int"
; pabResult : BYTE* out -> "var"
; pcbResult : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	tbs = windows.NewLazySystemDLL("tbs.dll")
	procTbsip_Submit_Command = tbs.NewProc("Tbsip_Submit_Command")
)

// hContext (void*), Locality (TBS_COMMAND_LOCALITY), Priority (TBS_COMMAND_PRIORITY), pabCommand (BYTE*), cbCommand (DWORD), pabResult (BYTE* out), pcbResult (DWORD* in/out)
r1, _, err := procTbsip_Submit_Command.Call(
	uintptr(hContext),
	uintptr(Locality),
	uintptr(Priority),
	uintptr(pabCommand),
	uintptr(cbCommand),
	uintptr(pabResult),
	uintptr(pcbResult),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function Tbsip_Submit_Command(
  hContext: Pointer;   // void*
  Locality: DWORD;   // TBS_COMMAND_LOCALITY
  Priority: DWORD;   // TBS_COMMAND_PRIORITY
  pabCommand: Pointer;   // BYTE*
  cbCommand: DWORD;   // DWORD
  pabResult: Pointer;   // BYTE* out
  pcbResult: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'tbs.dll' name 'Tbsip_Submit_Command';
result := DllCall("tbs\Tbsip_Submit_Command"
    , "Ptr", hContext   ; void*
    , "UInt", Locality   ; TBS_COMMAND_LOCALITY
    , "UInt", Priority   ; TBS_COMMAND_PRIORITY
    , "Ptr", pabCommand   ; BYTE*
    , "UInt", cbCommand   ; DWORD
    , "Ptr", pabResult   ; BYTE* out
    , "Ptr", pcbResult   ; DWORD* in/out
    , "UInt")   ; return: DWORD
●Tbsip_Submit_Command(hContext, Locality, Priority, pabCommand, cbCommand, pabResult, pcbResult) = DLL("tbs.dll", "dword Tbsip_Submit_Command(void*, dword, dword, void*, dword, void*, void*)")
# 呼び出し: Tbsip_Submit_Command(hContext, Locality, Priority, pabCommand, cbCommand, pabResult, pcbResult)
# hContext : void* -> "void*"
# Locality : TBS_COMMAND_LOCALITY -> "dword"
# Priority : TBS_COMMAND_PRIORITY -> "dword"
# pabCommand : BYTE* -> "void*"
# cbCommand : DWORD -> "dword"
# pabResult : BYTE* out -> "void*"
# pcbResult : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "tbs" fn Tbsip_Submit_Command(
    hContext: ?*anyopaque, // void*
    Locality: u32, // TBS_COMMAND_LOCALITY
    Priority: u32, // TBS_COMMAND_PRIORITY
    pabCommand: [*c]u8, // BYTE*
    cbCommand: u32, // DWORD
    pabResult: [*c]u8, // BYTE* out
    pcbResult: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) u32;
proc Tbsip_Submit_Command(
    hContext: pointer,  # void*
    Locality: uint32,  # TBS_COMMAND_LOCALITY
    Priority: uint32,  # TBS_COMMAND_PRIORITY
    pabCommand: ptr uint8,  # BYTE*
    cbCommand: uint32,  # DWORD
    pabResult: ptr uint8,  # BYTE* out
    pcbResult: ptr uint32  # DWORD* in/out
): uint32 {.importc: "Tbsip_Submit_Command", stdcall, dynlib: "tbs.dll".}
pragma(lib, "tbs");
extern(Windows)
uint Tbsip_Submit_Command(
    void* hContext,   // void*
    uint Locality,   // TBS_COMMAND_LOCALITY
    uint Priority,   // TBS_COMMAND_PRIORITY
    ubyte* pabCommand,   // BYTE*
    uint cbCommand,   // DWORD
    ubyte* pabResult,   // BYTE* out
    uint* pcbResult   // DWORD* in/out
);
ccall((:Tbsip_Submit_Command, "tbs.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, UInt32, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt8}, Ptr{UInt32}),
      hContext, Locality, Priority, pabCommand, cbCommand, pabResult, pcbResult)
# hContext : void* -> Ptr{Cvoid}
# Locality : TBS_COMMAND_LOCALITY -> UInt32
# Priority : TBS_COMMAND_PRIORITY -> UInt32
# pabCommand : BYTE* -> Ptr{UInt8}
# cbCommand : DWORD -> UInt32
# pabResult : BYTE* out -> Ptr{UInt8}
# pcbResult : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t Tbsip_Submit_Command(
    void* hContext,
    uint32_t Locality,
    uint32_t Priority,
    uint8_t* pabCommand,
    uint32_t cbCommand,
    uint8_t* pabResult,
    uint32_t* pcbResult);
]]
local tbs = ffi.load("tbs")
-- tbs.Tbsip_Submit_Command(hContext, Locality, Priority, pabCommand, cbCommand, pabResult, pcbResult)
-- hContext : void*
-- Locality : TBS_COMMAND_LOCALITY
-- Priority : TBS_COMMAND_PRIORITY
-- pabCommand : BYTE*
-- cbCommand : DWORD
-- pabResult : BYTE* out
-- pcbResult : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('tbs.dll');
const Tbsip_Submit_Command = lib.func('__stdcall', 'Tbsip_Submit_Command', 'uint32_t', ['void *', 'uint32_t', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint8_t *', 'uint32_t *']);
// Tbsip_Submit_Command(hContext, Locality, Priority, pabCommand, cbCommand, pabResult, pcbResult)
// hContext : void* -> 'void *'
// Locality : TBS_COMMAND_LOCALITY -> 'uint32_t'
// Priority : TBS_COMMAND_PRIORITY -> 'uint32_t'
// pabCommand : BYTE* -> 'uint8_t *'
// cbCommand : DWORD -> 'uint32_t'
// pabResult : BYTE* out -> 'uint8_t *'
// pcbResult : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("tbs.dll", {
  Tbsip_Submit_Command: { parameters: ["pointer", "u32", "u32", "pointer", "u32", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.Tbsip_Submit_Command(hContext, Locality, Priority, pabCommand, cbCommand, pabResult, pcbResult)
// hContext : void* -> "pointer"
// Locality : TBS_COMMAND_LOCALITY -> "u32"
// Priority : TBS_COMMAND_PRIORITY -> "u32"
// pabCommand : BYTE* -> "pointer"
// cbCommand : DWORD -> "u32"
// pabResult : BYTE* out -> "pointer"
// pcbResult : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t Tbsip_Submit_Command(
    void* hContext,
    uint32_t Locality,
    uint32_t Priority,
    uint8_t* pabCommand,
    uint32_t cbCommand,
    uint8_t* pabResult,
    uint32_t* pcbResult);
C, "tbs.dll");
// $ffi->Tbsip_Submit_Command(hContext, Locality, Priority, pabCommand, cbCommand, pabResult, pcbResult);
// hContext : void*
// Locality : TBS_COMMAND_LOCALITY
// Priority : TBS_COMMAND_PRIORITY
// pabCommand : BYTE*
// cbCommand : DWORD
// pabResult : BYTE* out
// pcbResult : DWORD* in/out
// 構造体/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 Tbs extends StdCallLibrary {
    Tbs INSTANCE = Native.load("tbs", Tbs.class);
    int Tbsip_Submit_Command(
        Pointer hContext,   // void*
        int Locality,   // TBS_COMMAND_LOCALITY
        int Priority,   // TBS_COMMAND_PRIORITY
        byte[] pabCommand,   // BYTE*
        int cbCommand,   // DWORD
        byte[] pabResult,   // BYTE* out
        IntByReference pcbResult   // DWORD* in/out
    );
}
@[Link("tbs")]
lib Libtbs
  fun Tbsip_Submit_Command = Tbsip_Submit_Command(
    hContext : Void*,   # void*
    Locality : UInt32,   # TBS_COMMAND_LOCALITY
    Priority : UInt32,   # TBS_COMMAND_PRIORITY
    pabCommand : UInt8*,   # BYTE*
    cbCommand : UInt32,   # DWORD
    pabResult : UInt8*,   # BYTE* out
    pcbResult : UInt32*   # DWORD* in/out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef Tbsip_Submit_CommandNative = Uint32 Function(Pointer<Void>, Uint32, Uint32, Pointer<Uint8>, Uint32, Pointer<Uint8>, Pointer<Uint32>);
typedef Tbsip_Submit_CommandDart = int Function(Pointer<Void>, int, int, Pointer<Uint8>, int, Pointer<Uint8>, Pointer<Uint32>);
final Tbsip_Submit_Command = DynamicLibrary.open('tbs.dll')
    .lookupFunction<Tbsip_Submit_CommandNative, Tbsip_Submit_CommandDart>('Tbsip_Submit_Command');
// hContext : void* -> Pointer<Void>
// Locality : TBS_COMMAND_LOCALITY -> Uint32
// Priority : TBS_COMMAND_PRIORITY -> Uint32
// pabCommand : BYTE* -> Pointer<Uint8>
// cbCommand : DWORD -> Uint32
// pabResult : BYTE* out -> Pointer<Uint8>
// pcbResult : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function Tbsip_Submit_Command(
  hContext: Pointer;   // void*
  Locality: DWORD;   // TBS_COMMAND_LOCALITY
  Priority: DWORD;   // TBS_COMMAND_PRIORITY
  pabCommand: Pointer;   // BYTE*
  cbCommand: DWORD;   // DWORD
  pabResult: Pointer;   // BYTE* out
  pcbResult: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'tbs.dll' name 'Tbsip_Submit_Command';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "Tbsip_Submit_Command"
  c_Tbsip_Submit_Command :: Ptr () -> Word32 -> Word32 -> Ptr Word8 -> Word32 -> Ptr Word8 -> Ptr Word32 -> IO Word32
-- hContext : void* -> Ptr ()
-- Locality : TBS_COMMAND_LOCALITY -> Word32
-- Priority : TBS_COMMAND_PRIORITY -> Word32
-- pabCommand : BYTE* -> Ptr Word8
-- cbCommand : DWORD -> Word32
-- pabResult : BYTE* out -> Ptr Word8
-- pcbResult : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let tbsip_submit_command =
  foreign "Tbsip_Submit_Command"
    ((ptr void) @-> uint32_t @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint8_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* hContext : void* -> (ptr void) *)
(* Locality : TBS_COMMAND_LOCALITY -> uint32_t *)
(* Priority : TBS_COMMAND_PRIORITY -> uint32_t *)
(* pabCommand : BYTE* -> (ptr uint8_t) *)
(* cbCommand : DWORD -> uint32_t *)
(* pabResult : BYTE* out -> (ptr uint8_t) *)
(* pcbResult : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library tbs (t "tbs.dll"))
(cffi:use-foreign-library tbs)

(cffi:defcfun ("Tbsip_Submit_Command" tbsip-submit-command :convention :stdcall) :uint32
  (h-context :pointer)   ; void*
  (locality :uint32)   ; TBS_COMMAND_LOCALITY
  (priority :uint32)   ; TBS_COMMAND_PRIORITY
  (pab-command :pointer)   ; BYTE*
  (cb-command :uint32)   ; DWORD
  (pab-result :pointer)   ; BYTE* out
  (pcb-result :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $Tbsip_Submit_Command = Win32::API::More->new('tbs',
    'DWORD Tbsip_Submit_Command(LPVOID hContext, DWORD Locality, DWORD Priority, LPVOID pabCommand, DWORD cbCommand, LPVOID pabResult, LPVOID pcbResult)');
# my $ret = $Tbsip_Submit_Command->Call($hContext, $Locality, $Priority, $pabCommand, $cbCommand, $pabResult, $pcbResult);
# hContext : void* -> LPVOID
# Locality : TBS_COMMAND_LOCALITY -> DWORD
# Priority : TBS_COMMAND_PRIORITY -> DWORD
# pabCommand : BYTE* -> LPVOID
# cbCommand : DWORD -> DWORD
# pabResult : BYTE* out -> LPVOID
# pcbResult : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型