ホーム › System.TpmBaseServices › GetDeviceIDString
GetDeviceIDString
関数TPMで保護されたデバイスIDを文字列で取得する。
シグネチャ
// tbs.dll
#include <windows.h>
HRESULT GetDeviceIDString(
LPWSTR pszWindowsAIK, // optional
DWORD cchWindowsAIK,
DWORD* pcchResult,
BOOL* pfProtectedByTPM // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszWindowsAIK | LPWSTR | outoptional | デバイスIDを文字列(Unicode)で格納する出力バッファへのポインタ。 |
| cchWindowsAIK | DWORD | in | 出力バッファの容量(文字数)。 |
| pcchResult | DWORD* | out | 実際に書き込まれた(または必要な)文字数を受け取る出力先(DWORD*)。 |
| pfProtectedByTPM | BOOL* | outoptional | そのIDがTPMで保護されているかを受け取る出力先(BOOL*)。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// tbs.dll
#include <windows.h>
HRESULT GetDeviceIDString(
LPWSTR pszWindowsAIK, // optional
DWORD cchWindowsAIK,
DWORD* pcchResult,
BOOL* pfProtectedByTPM // optional
);[DllImport("tbs.dll", ExactSpelling = true)]
static extern int GetDeviceIDString(
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszWindowsAIK, // LPWSTR optional, out
uint cchWindowsAIK, // DWORD
out uint pcchResult, // DWORD* out
IntPtr pfProtectedByTPM // BOOL* optional, out
);<DllImport("tbs.dll", ExactSpelling:=True)>
Public Shared Function GetDeviceIDString(
<MarshalAs(UnmanagedType.LPWStr)> pszWindowsAIK As System.Text.StringBuilder, ' LPWSTR optional, out
cchWindowsAIK As UInteger, ' DWORD
<Out> ByRef pcchResult As UInteger, ' DWORD* out
pfProtectedByTPM As IntPtr ' BOOL* optional, out
) As Integer
End Function' pszWindowsAIK : LPWSTR optional, out
' cchWindowsAIK : DWORD
' pcchResult : DWORD* out
' pfProtectedByTPM : BOOL* optional, out
Declare PtrSafe Function GetDeviceIDString Lib "tbs" ( _
ByVal pszWindowsAIK As LongPtr, _
ByVal cchWindowsAIK As Long, _
ByRef pcchResult As Long, _
ByVal pfProtectedByTPM As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetDeviceIDString = ctypes.windll.tbs.GetDeviceIDString
GetDeviceIDString.restype = ctypes.c_int
GetDeviceIDString.argtypes = [
wintypes.LPWSTR, # pszWindowsAIK : LPWSTR optional, out
wintypes.DWORD, # cchWindowsAIK : DWORD
ctypes.POINTER(wintypes.DWORD), # pcchResult : DWORD* out
ctypes.c_void_p, # pfProtectedByTPM : BOOL* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('tbs.dll')
GetDeviceIDString = Fiddle::Function.new(
lib['GetDeviceIDString'],
[
Fiddle::TYPE_VOIDP, # pszWindowsAIK : LPWSTR optional, out
-Fiddle::TYPE_INT, # cchWindowsAIK : DWORD
Fiddle::TYPE_VOIDP, # pcchResult : DWORD* out
Fiddle::TYPE_VOIDP, # pfProtectedByTPM : BOOL* optional, out
],
Fiddle::TYPE_INT)#[link(name = "tbs")]
extern "system" {
fn GetDeviceIDString(
pszWindowsAIK: *mut u16, // LPWSTR optional, out
cchWindowsAIK: u32, // DWORD
pcchResult: *mut u32, // DWORD* out
pfProtectedByTPM: *mut i32 // BOOL* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("tbs.dll")]
public static extern int GetDeviceIDString([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszWindowsAIK, uint cchWindowsAIK, out uint pcchResult, IntPtr pfProtectedByTPM);
"@
$api = Add-Type -MemberDefinition $sig -Name 'tbs_GetDeviceIDString' -Namespace Win32 -PassThru
# $api::GetDeviceIDString(pszWindowsAIK, cchWindowsAIK, pcchResult, pfProtectedByTPM)#uselib "tbs.dll"
#func global GetDeviceIDString "GetDeviceIDString" sptr, sptr, sptr, sptr
; GetDeviceIDString varptr(pszWindowsAIK), cchWindowsAIK, varptr(pcchResult), varptr(pfProtectedByTPM) ; 戻り値は stat
; pszWindowsAIK : LPWSTR optional, out -> "sptr"
; cchWindowsAIK : DWORD -> "sptr"
; pcchResult : DWORD* out -> "sptr"
; pfProtectedByTPM : BOOL* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "tbs.dll" #cfunc global GetDeviceIDString "GetDeviceIDString" var, int, var, var ; res = GetDeviceIDString(pszWindowsAIK, cchWindowsAIK, pcchResult, pfProtectedByTPM) ; pszWindowsAIK : LPWSTR optional, out -> "var" ; cchWindowsAIK : DWORD -> "int" ; pcchResult : DWORD* out -> "var" ; pfProtectedByTPM : BOOL* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "tbs.dll" #cfunc global GetDeviceIDString "GetDeviceIDString" sptr, int, sptr, sptr ; res = GetDeviceIDString(varptr(pszWindowsAIK), cchWindowsAIK, varptr(pcchResult), varptr(pfProtectedByTPM)) ; pszWindowsAIK : LPWSTR optional, out -> "sptr" ; cchWindowsAIK : DWORD -> "int" ; pcchResult : DWORD* out -> "sptr" ; pfProtectedByTPM : BOOL* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT GetDeviceIDString(LPWSTR pszWindowsAIK, DWORD cchWindowsAIK, DWORD* pcchResult, BOOL* pfProtectedByTPM) #uselib "tbs.dll" #cfunc global GetDeviceIDString "GetDeviceIDString" var, int, var, var ; res = GetDeviceIDString(pszWindowsAIK, cchWindowsAIK, pcchResult, pfProtectedByTPM) ; pszWindowsAIK : LPWSTR optional, out -> "var" ; cchWindowsAIK : DWORD -> "int" ; pcchResult : DWORD* out -> "var" ; pfProtectedByTPM : BOOL* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT GetDeviceIDString(LPWSTR pszWindowsAIK, DWORD cchWindowsAIK, DWORD* pcchResult, BOOL* pfProtectedByTPM) #uselib "tbs.dll" #cfunc global GetDeviceIDString "GetDeviceIDString" intptr, int, intptr, intptr ; res = GetDeviceIDString(varptr(pszWindowsAIK), cchWindowsAIK, varptr(pcchResult), varptr(pfProtectedByTPM)) ; pszWindowsAIK : LPWSTR optional, out -> "intptr" ; cchWindowsAIK : DWORD -> "int" ; pcchResult : DWORD* out -> "intptr" ; pfProtectedByTPM : BOOL* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
tbs = windows.NewLazySystemDLL("tbs.dll")
procGetDeviceIDString = tbs.NewProc("GetDeviceIDString")
)
// pszWindowsAIK (LPWSTR optional, out), cchWindowsAIK (DWORD), pcchResult (DWORD* out), pfProtectedByTPM (BOOL* optional, out)
r1, _, err := procGetDeviceIDString.Call(
uintptr(pszWindowsAIK),
uintptr(cchWindowsAIK),
uintptr(pcchResult),
uintptr(pfProtectedByTPM),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction GetDeviceIDString(
pszWindowsAIK: PWideChar; // LPWSTR optional, out
cchWindowsAIK: DWORD; // DWORD
pcchResult: Pointer; // DWORD* out
pfProtectedByTPM: Pointer // BOOL* optional, out
): Integer; stdcall;
external 'tbs.dll' name 'GetDeviceIDString';result := DllCall("tbs\GetDeviceIDString"
, "Ptr", pszWindowsAIK ; LPWSTR optional, out
, "UInt", cchWindowsAIK ; DWORD
, "Ptr", pcchResult ; DWORD* out
, "Ptr", pfProtectedByTPM ; BOOL* optional, out
, "Int") ; return: HRESULT●GetDeviceIDString(pszWindowsAIK, cchWindowsAIK, pcchResult, pfProtectedByTPM) = DLL("tbs.dll", "int GetDeviceIDString(char*, dword, void*, void*)")
# 呼び出し: GetDeviceIDString(pszWindowsAIK, cchWindowsAIK, pcchResult, pfProtectedByTPM)
# pszWindowsAIK : LPWSTR optional, out -> "char*"
# cchWindowsAIK : DWORD -> "dword"
# pcchResult : DWORD* out -> "void*"
# pfProtectedByTPM : BOOL* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "tbs" fn GetDeviceIDString(
pszWindowsAIK: [*c]u16, // LPWSTR optional, out
cchWindowsAIK: u32, // DWORD
pcchResult: [*c]u32, // DWORD* out
pfProtectedByTPM: [*c]i32 // BOOL* optional, out
) callconv(std.os.windows.WINAPI) i32;proc GetDeviceIDString(
pszWindowsAIK: ptr uint16, # LPWSTR optional, out
cchWindowsAIK: uint32, # DWORD
pcchResult: ptr uint32, # DWORD* out
pfProtectedByTPM: ptr int32 # BOOL* optional, out
): int32 {.importc: "GetDeviceIDString", stdcall, dynlib: "tbs.dll".}pragma(lib, "tbs");
extern(Windows)
int GetDeviceIDString(
wchar* pszWindowsAIK, // LPWSTR optional, out
uint cchWindowsAIK, // DWORD
uint* pcchResult, // DWORD* out
int* pfProtectedByTPM // BOOL* optional, out
);ccall((:GetDeviceIDString, "tbs.dll"), stdcall, Int32,
(Ptr{UInt16}, UInt32, Ptr{UInt32}, Ptr{Int32}),
pszWindowsAIK, cchWindowsAIK, pcchResult, pfProtectedByTPM)
# pszWindowsAIK : LPWSTR optional, out -> Ptr{UInt16}
# cchWindowsAIK : DWORD -> UInt32
# pcchResult : DWORD* out -> Ptr{UInt32}
# pfProtectedByTPM : BOOL* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetDeviceIDString(
uint16_t* pszWindowsAIK,
uint32_t cchWindowsAIK,
uint32_t* pcchResult,
int32_t* pfProtectedByTPM);
]]
local tbs = ffi.load("tbs")
-- tbs.GetDeviceIDString(pszWindowsAIK, cchWindowsAIK, pcchResult, pfProtectedByTPM)
-- pszWindowsAIK : LPWSTR optional, out
-- cchWindowsAIK : DWORD
-- pcchResult : DWORD* out
-- pfProtectedByTPM : BOOL* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('tbs.dll');
const GetDeviceIDString = lib.func('__stdcall', 'GetDeviceIDString', 'int32_t', ['uint16_t *', 'uint32_t', 'uint32_t *', 'int32_t *']);
// GetDeviceIDString(pszWindowsAIK, cchWindowsAIK, pcchResult, pfProtectedByTPM)
// pszWindowsAIK : LPWSTR optional, out -> 'uint16_t *'
// cchWindowsAIK : DWORD -> 'uint32_t'
// pcchResult : DWORD* out -> 'uint32_t *'
// pfProtectedByTPM : BOOL* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("tbs.dll", {
GetDeviceIDString: { parameters: ["buffer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.GetDeviceIDString(pszWindowsAIK, cchWindowsAIK, pcchResult, pfProtectedByTPM)
// pszWindowsAIK : LPWSTR optional, out -> "buffer"
// cchWindowsAIK : DWORD -> "u32"
// pcchResult : DWORD* out -> "pointer"
// pfProtectedByTPM : BOOL* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetDeviceIDString(
uint16_t* pszWindowsAIK,
uint32_t cchWindowsAIK,
uint32_t* pcchResult,
int32_t* pfProtectedByTPM);
C, "tbs.dll");
// $ffi->GetDeviceIDString(pszWindowsAIK, cchWindowsAIK, pcchResult, pfProtectedByTPM);
// pszWindowsAIK : LPWSTR optional, out
// cchWindowsAIK : DWORD
// pcchResult : DWORD* out
// pfProtectedByTPM : BOOL* optional, 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 GetDeviceIDString(
char[] pszWindowsAIK, // LPWSTR optional, out
int cchWindowsAIK, // DWORD
IntByReference pcchResult, // DWORD* out
IntByReference pfProtectedByTPM // BOOL* optional, out
);
}@[Link("tbs")]
lib Libtbs
fun GetDeviceIDString = GetDeviceIDString(
pszWindowsAIK : UInt16*, # LPWSTR optional, out
cchWindowsAIK : UInt32, # DWORD
pcchResult : UInt32*, # DWORD* out
pfProtectedByTPM : Int32* # BOOL* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetDeviceIDStringNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Uint32>, Pointer<Int32>);
typedef GetDeviceIDStringDart = int Function(Pointer<Utf16>, int, Pointer<Uint32>, Pointer<Int32>);
final GetDeviceIDString = DynamicLibrary.open('tbs.dll')
.lookupFunction<GetDeviceIDStringNative, GetDeviceIDStringDart>('GetDeviceIDString');
// pszWindowsAIK : LPWSTR optional, out -> Pointer<Utf16>
// cchWindowsAIK : DWORD -> Uint32
// pcchResult : DWORD* out -> Pointer<Uint32>
// pfProtectedByTPM : BOOL* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetDeviceIDString(
pszWindowsAIK: PWideChar; // LPWSTR optional, out
cchWindowsAIK: DWORD; // DWORD
pcchResult: Pointer; // DWORD* out
pfProtectedByTPM: Pointer // BOOL* optional, out
): Integer; stdcall;
external 'tbs.dll' name 'GetDeviceIDString';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetDeviceIDString"
c_GetDeviceIDString :: CWString -> Word32 -> Ptr Word32 -> Ptr CInt -> IO Int32
-- pszWindowsAIK : LPWSTR optional, out -> CWString
-- cchWindowsAIK : DWORD -> Word32
-- pcchResult : DWORD* out -> Ptr Word32
-- pfProtectedByTPM : BOOL* optional, out -> Ptr CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getdeviceidstring =
foreign "GetDeviceIDString"
((ptr uint16_t) @-> uint32_t @-> (ptr uint32_t) @-> (ptr int32_t) @-> returning int32_t)
(* pszWindowsAIK : LPWSTR optional, out -> (ptr uint16_t) *)
(* cchWindowsAIK : DWORD -> uint32_t *)
(* pcchResult : DWORD* out -> (ptr uint32_t) *)
(* pfProtectedByTPM : BOOL* optional, out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library tbs (t "tbs.dll"))
(cffi:use-foreign-library tbs)
(cffi:defcfun ("GetDeviceIDString" get-device-idstring :convention :stdcall) :int32
(psz-windows-aik :pointer) ; LPWSTR optional, out
(cch-windows-aik :uint32) ; DWORD
(pcch-result :pointer) ; DWORD* out
(pf-protected-by-tpm :pointer)) ; BOOL* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetDeviceIDString = Win32::API::More->new('tbs',
'int GetDeviceIDString(LPWSTR pszWindowsAIK, DWORD cchWindowsAIK, LPVOID pcchResult, LPVOID pfProtectedByTPM)');
# my $ret = $GetDeviceIDString->Call($pszWindowsAIK, $cchWindowsAIK, $pcchResult, $pfProtectedByTPM);
# pszWindowsAIK : LPWSTR optional, out -> LPWSTR
# cchWindowsAIK : DWORD -> DWORD
# pcchResult : DWORD* out -> LPVOID
# pfProtectedByTPM : BOOL* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。