ホーム › System.TpmBaseServices › Tbsi_Context_Create
Tbsi_Context_Create
関数TPM基本サービス(TBS)のコンテキストを作成する。
シグネチャ
// tbs.dll
#include <windows.h>
DWORD Tbsi_Context_Create(
TBS_CONTEXT_PARAMS* pContextParams,
void** phContext
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pContextParams | TBS_CONTEXT_PARAMS* | in | 作成するTBSコンテキストのバージョン等を指定するTBS_CONTEXT_PARAMS構造体へのポインタ。 |
| phContext | void** | out | 作成されたTBSコンテキストハンドルを受け取る出力先(void**)。 |
戻り値の型: DWORD
各言語での呼び出し定義
// tbs.dll
#include <windows.h>
DWORD Tbsi_Context_Create(
TBS_CONTEXT_PARAMS* pContextParams,
void** phContext
);[DllImport("tbs.dll", ExactSpelling = true)]
static extern uint Tbsi_Context_Create(
IntPtr pContextParams, // TBS_CONTEXT_PARAMS*
IntPtr phContext // void** out
);<DllImport("tbs.dll", ExactSpelling:=True)>
Public Shared Function Tbsi_Context_Create(
pContextParams As IntPtr, ' TBS_CONTEXT_PARAMS*
phContext As IntPtr ' void** out
) As UInteger
End Function' pContextParams : TBS_CONTEXT_PARAMS*
' phContext : void** out
Declare PtrSafe Function Tbsi_Context_Create Lib "tbs" ( _
ByVal pContextParams As LongPtr, _
ByVal phContext As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
Tbsi_Context_Create = ctypes.windll.tbs.Tbsi_Context_Create
Tbsi_Context_Create.restype = wintypes.DWORD
Tbsi_Context_Create.argtypes = [
ctypes.c_void_p, # pContextParams : TBS_CONTEXT_PARAMS*
ctypes.c_void_p, # phContext : void** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('tbs.dll')
Tbsi_Context_Create = Fiddle::Function.new(
lib['Tbsi_Context_Create'],
[
Fiddle::TYPE_VOIDP, # pContextParams : TBS_CONTEXT_PARAMS*
Fiddle::TYPE_VOIDP, # phContext : void** out
],
-Fiddle::TYPE_INT)#[link(name = "tbs")]
extern "system" {
fn Tbsi_Context_Create(
pContextParams: *mut TBS_CONTEXT_PARAMS, // TBS_CONTEXT_PARAMS*
phContext: *mut *mut () // void** out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("tbs.dll")]
public static extern uint Tbsi_Context_Create(IntPtr pContextParams, IntPtr phContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'tbs_Tbsi_Context_Create' -Namespace Win32 -PassThru
# $api::Tbsi_Context_Create(pContextParams, phContext)#uselib "tbs.dll"
#func global Tbsi_Context_Create "Tbsi_Context_Create" sptr, sptr
; Tbsi_Context_Create varptr(pContextParams), phContext ; 戻り値は stat
; pContextParams : TBS_CONTEXT_PARAMS* -> "sptr"
; phContext : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "tbs.dll" #cfunc global Tbsi_Context_Create "Tbsi_Context_Create" var, sptr ; res = Tbsi_Context_Create(pContextParams, phContext) ; pContextParams : TBS_CONTEXT_PARAMS* -> "var" ; phContext : void** out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "tbs.dll" #cfunc global Tbsi_Context_Create "Tbsi_Context_Create" sptr, sptr ; res = Tbsi_Context_Create(varptr(pContextParams), phContext) ; pContextParams : TBS_CONTEXT_PARAMS* -> "sptr" ; phContext : void** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD Tbsi_Context_Create(TBS_CONTEXT_PARAMS* pContextParams, void** phContext) #uselib "tbs.dll" #cfunc global Tbsi_Context_Create "Tbsi_Context_Create" var, intptr ; res = Tbsi_Context_Create(pContextParams, phContext) ; pContextParams : TBS_CONTEXT_PARAMS* -> "var" ; phContext : void** out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD Tbsi_Context_Create(TBS_CONTEXT_PARAMS* pContextParams, void** phContext) #uselib "tbs.dll" #cfunc global Tbsi_Context_Create "Tbsi_Context_Create" intptr, intptr ; res = Tbsi_Context_Create(varptr(pContextParams), phContext) ; pContextParams : TBS_CONTEXT_PARAMS* -> "intptr" ; phContext : void** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
tbs = windows.NewLazySystemDLL("tbs.dll")
procTbsi_Context_Create = tbs.NewProc("Tbsi_Context_Create")
)
// pContextParams (TBS_CONTEXT_PARAMS*), phContext (void** out)
r1, _, err := procTbsi_Context_Create.Call(
uintptr(pContextParams),
uintptr(phContext),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction Tbsi_Context_Create(
pContextParams: Pointer; // TBS_CONTEXT_PARAMS*
phContext: Pointer // void** out
): DWORD; stdcall;
external 'tbs.dll' name 'Tbsi_Context_Create';result := DllCall("tbs\Tbsi_Context_Create"
, "Ptr", pContextParams ; TBS_CONTEXT_PARAMS*
, "Ptr", phContext ; void** out
, "UInt") ; return: DWORD●Tbsi_Context_Create(pContextParams, phContext) = DLL("tbs.dll", "dword Tbsi_Context_Create(void*, void*)")
# 呼び出し: Tbsi_Context_Create(pContextParams, phContext)
# pContextParams : TBS_CONTEXT_PARAMS* -> "void*"
# phContext : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "tbs" fn Tbsi_Context_Create(
pContextParams: [*c]TBS_CONTEXT_PARAMS, // TBS_CONTEXT_PARAMS*
phContext: ?*anyopaque // void** out
) callconv(std.os.windows.WINAPI) u32;proc Tbsi_Context_Create(
pContextParams: ptr TBS_CONTEXT_PARAMS, # TBS_CONTEXT_PARAMS*
phContext: pointer # void** out
): uint32 {.importc: "Tbsi_Context_Create", stdcall, dynlib: "tbs.dll".}pragma(lib, "tbs");
extern(Windows)
uint Tbsi_Context_Create(
TBS_CONTEXT_PARAMS* pContextParams, // TBS_CONTEXT_PARAMS*
void** phContext // void** out
);ccall((:Tbsi_Context_Create, "tbs.dll"), stdcall, UInt32,
(Ptr{TBS_CONTEXT_PARAMS}, Ptr{Cvoid}),
pContextParams, phContext)
# pContextParams : TBS_CONTEXT_PARAMS* -> Ptr{TBS_CONTEXT_PARAMS}
# phContext : void** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t Tbsi_Context_Create(
void* pContextParams,
void** phContext);
]]
local tbs = ffi.load("tbs")
-- tbs.Tbsi_Context_Create(pContextParams, phContext)
-- pContextParams : TBS_CONTEXT_PARAMS*
-- phContext : void** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('tbs.dll');
const Tbsi_Context_Create = lib.func('__stdcall', 'Tbsi_Context_Create', 'uint32_t', ['void *', 'void *']);
// Tbsi_Context_Create(pContextParams, phContext)
// pContextParams : TBS_CONTEXT_PARAMS* -> 'void *'
// phContext : void** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("tbs.dll", {
Tbsi_Context_Create: { parameters: ["pointer", "pointer"], result: "u32" },
});
// lib.symbols.Tbsi_Context_Create(pContextParams, phContext)
// pContextParams : TBS_CONTEXT_PARAMS* -> "pointer"
// phContext : void** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t Tbsi_Context_Create(
void* pContextParams,
void** phContext);
C, "tbs.dll");
// $ffi->Tbsi_Context_Create(pContextParams, phContext);
// pContextParams : TBS_CONTEXT_PARAMS*
// phContext : void** 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 Tbsi_Context_Create(
Pointer pContextParams, // TBS_CONTEXT_PARAMS*
Pointer phContext // void** out
);
}@[Link("tbs")]
lib Libtbs
fun Tbsi_Context_Create = Tbsi_Context_Create(
pContextParams : TBS_CONTEXT_PARAMS*, # TBS_CONTEXT_PARAMS*
phContext : Void** # void** out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef Tbsi_Context_CreateNative = Uint32 Function(Pointer<Void>, Pointer<Void>);
typedef Tbsi_Context_CreateDart = int Function(Pointer<Void>, Pointer<Void>);
final Tbsi_Context_Create = DynamicLibrary.open('tbs.dll')
.lookupFunction<Tbsi_Context_CreateNative, Tbsi_Context_CreateDart>('Tbsi_Context_Create');
// pContextParams : TBS_CONTEXT_PARAMS* -> Pointer<Void>
// phContext : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function Tbsi_Context_Create(
pContextParams: Pointer; // TBS_CONTEXT_PARAMS*
phContext: Pointer // void** out
): DWORD; stdcall;
external 'tbs.dll' name 'Tbsi_Context_Create';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "Tbsi_Context_Create"
c_Tbsi_Context_Create :: Ptr () -> Ptr () -> IO Word32
-- pContextParams : TBS_CONTEXT_PARAMS* -> Ptr ()
-- phContext : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let tbsi_context_create =
foreign "Tbsi_Context_Create"
((ptr void) @-> (ptr void) @-> returning uint32_t)
(* pContextParams : TBS_CONTEXT_PARAMS* -> (ptr void) *)
(* phContext : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library tbs (t "tbs.dll"))
(cffi:use-foreign-library tbs)
(cffi:defcfun ("Tbsi_Context_Create" tbsi-context-create :convention :stdcall) :uint32
(p-context-params :pointer) ; TBS_CONTEXT_PARAMS*
(ph-context :pointer)) ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $Tbsi_Context_Create = Win32::API::More->new('tbs',
'DWORD Tbsi_Context_Create(LPVOID pContextParams, LPVOID phContext)');
# my $ret = $Tbsi_Context_Create->Call($pContextParams, $phContext);
# pContextParams : TBS_CONTEXT_PARAMS* -> LPVOID
# phContext : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型