Win32 API 日本語リファレンス
ホームNetworkManagement.P2P › PeerIdentityGetCryptKey

PeerIdentityGetCryptKey

関数
ピアアイデンティティの暗号化キーを取得する。
DLLP2P.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT PeerIdentityGetCryptKey(
    LPCWSTR pwzIdentity,   // optional
    UINT_PTR* phCryptProv
);

パラメーター

名前方向説明
pwzIdentityLPCWSTRinoptional暗号鍵を取得する対象のピア識別子を示す文字列へのポインター。
phCryptProvUINT_PTR*out識別子に関連付けられた暗号化プロバイダーのハンドルを受け取る出力ポインター。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT PeerIdentityGetCryptKey(
    LPCWSTR pwzIdentity,   // optional
    UINT_PTR* phCryptProv
);
[DllImport("P2P.dll", ExactSpelling = true)]
static extern int PeerIdentityGetCryptKey(
    [MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity,   // LPCWSTR optional
    out UIntPtr phCryptProv   // UINT_PTR* out
);
<DllImport("P2P.dll", ExactSpelling:=True)>
Public Shared Function PeerIdentityGetCryptKey(
    <MarshalAs(UnmanagedType.LPWStr)> pwzIdentity As String,   ' LPCWSTR optional
    <Out> ByRef phCryptProv As UIntPtr   ' UINT_PTR* out
) As Integer
End Function
' pwzIdentity : LPCWSTR optional
' phCryptProv : UINT_PTR* out
Declare PtrSafe Function PeerIdentityGetCryptKey Lib "p2p" ( _
    ByVal pwzIdentity As LongPtr, _
    ByRef phCryptProv As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PeerIdentityGetCryptKey = ctypes.windll.p2p.PeerIdentityGetCryptKey
PeerIdentityGetCryptKey.restype = ctypes.c_int
PeerIdentityGetCryptKey.argtypes = [
    wintypes.LPCWSTR,  # pwzIdentity : LPCWSTR optional
    ctypes.POINTER(ctypes.c_size_t),  # phCryptProv : UINT_PTR* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('P2P.dll')
PeerIdentityGetCryptKey = Fiddle::Function.new(
  lib['PeerIdentityGetCryptKey'],
  [
    Fiddle::TYPE_VOIDP,  # pwzIdentity : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # phCryptProv : UINT_PTR* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "p2p")]
extern "system" {
    fn PeerIdentityGetCryptKey(
        pwzIdentity: *const u16,  // LPCWSTR optional
        phCryptProv: *mut usize  // UINT_PTR* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("P2P.dll")]
public static extern int PeerIdentityGetCryptKey([MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity, out UIntPtr phCryptProv);
"@
$api = Add-Type -MemberDefinition $sig -Name 'P2P_PeerIdentityGetCryptKey' -Namespace Win32 -PassThru
# $api::PeerIdentityGetCryptKey(pwzIdentity, phCryptProv)
#uselib "P2P.dll"
#func global PeerIdentityGetCryptKey "PeerIdentityGetCryptKey" sptr, sptr
; PeerIdentityGetCryptKey pwzIdentity, varptr(phCryptProv)   ; 戻り値は stat
; pwzIdentity : LPCWSTR optional -> "sptr"
; phCryptProv : UINT_PTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "P2P.dll"
#cfunc global PeerIdentityGetCryptKey "PeerIdentityGetCryptKey" wstr, var
; res = PeerIdentityGetCryptKey(pwzIdentity, phCryptProv)
; pwzIdentity : LPCWSTR optional -> "wstr"
; phCryptProv : UINT_PTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT PeerIdentityGetCryptKey(LPCWSTR pwzIdentity, UINT_PTR* phCryptProv)
#uselib "P2P.dll"
#cfunc global PeerIdentityGetCryptKey "PeerIdentityGetCryptKey" wstr, var
; res = PeerIdentityGetCryptKey(pwzIdentity, phCryptProv)
; pwzIdentity : LPCWSTR optional -> "wstr"
; phCryptProv : UINT_PTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	p2p = windows.NewLazySystemDLL("P2P.dll")
	procPeerIdentityGetCryptKey = p2p.NewProc("PeerIdentityGetCryptKey")
)

// pwzIdentity (LPCWSTR optional), phCryptProv (UINT_PTR* out)
r1, _, err := procPeerIdentityGetCryptKey.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwzIdentity))),
	uintptr(phCryptProv),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function PeerIdentityGetCryptKey(
  pwzIdentity: PWideChar;   // LPCWSTR optional
  phCryptProv: Pointer   // UINT_PTR* out
): Integer; stdcall;
  external 'P2P.dll' name 'PeerIdentityGetCryptKey';
result := DllCall("P2P\PeerIdentityGetCryptKey"
    , "WStr", pwzIdentity   ; LPCWSTR optional
    , "Ptr", phCryptProv   ; UINT_PTR* out
    , "Int")   ; return: HRESULT
●PeerIdentityGetCryptKey(pwzIdentity, phCryptProv) = DLL("P2P.dll", "int PeerIdentityGetCryptKey(char*, void*)")
# 呼び出し: PeerIdentityGetCryptKey(pwzIdentity, phCryptProv)
# pwzIdentity : LPCWSTR optional -> "char*"
# phCryptProv : UINT_PTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "p2p" fn PeerIdentityGetCryptKey(
    pwzIdentity: [*c]const u16, // LPCWSTR optional
    phCryptProv: [*c]usize // UINT_PTR* out
) callconv(std.os.windows.WINAPI) i32;
proc PeerIdentityGetCryptKey(
    pwzIdentity: WideCString,  # LPCWSTR optional
    phCryptProv: ptr uint  # UINT_PTR* out
): int32 {.importc: "PeerIdentityGetCryptKey", stdcall, dynlib: "P2P.dll".}
pragma(lib, "p2p");
extern(Windows)
int PeerIdentityGetCryptKey(
    const(wchar)* pwzIdentity,   // LPCWSTR optional
    size_t* phCryptProv   // UINT_PTR* out
);
ccall((:PeerIdentityGetCryptKey, "P2P.dll"), stdcall, Int32,
      (Cwstring, Ptr{Csize_t}),
      pwzIdentity, phCryptProv)
# pwzIdentity : LPCWSTR optional -> Cwstring
# phCryptProv : UINT_PTR* out -> Ptr{Csize_t}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t PeerIdentityGetCryptKey(
    const uint16_t* pwzIdentity,
    uintptr_t* phCryptProv);
]]
local p2p = ffi.load("p2p")
-- p2p.PeerIdentityGetCryptKey(pwzIdentity, phCryptProv)
-- pwzIdentity : LPCWSTR optional
-- phCryptProv : UINT_PTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('P2P.dll');
const PeerIdentityGetCryptKey = lib.func('__stdcall', 'PeerIdentityGetCryptKey', 'int32_t', ['str16', 'uintptr_t *']);
// PeerIdentityGetCryptKey(pwzIdentity, phCryptProv)
// pwzIdentity : LPCWSTR optional -> 'str16'
// phCryptProv : UINT_PTR* out -> 'uintptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("P2P.dll", {
  PeerIdentityGetCryptKey: { parameters: ["buffer", "pointer"], result: "i32" },
});
// lib.symbols.PeerIdentityGetCryptKey(pwzIdentity, phCryptProv)
// pwzIdentity : LPCWSTR optional -> "buffer"
// phCryptProv : UINT_PTR* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t PeerIdentityGetCryptKey(
    const uint16_t* pwzIdentity,
    size_t* phCryptProv);
C, "P2P.dll");
// $ffi->PeerIdentityGetCryptKey(pwzIdentity, phCryptProv);
// pwzIdentity : LPCWSTR optional
// phCryptProv : UINT_PTR* 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 P2p extends StdCallLibrary {
    P2p INSTANCE = Native.load("p2p", P2p.class);
    int PeerIdentityGetCryptKey(
        WString pwzIdentity,   // LPCWSTR optional
        LongByReference phCryptProv   // UINT_PTR* out
    );
}
@[Link("p2p")]
lib LibP2P
  fun PeerIdentityGetCryptKey = PeerIdentityGetCryptKey(
    pwzIdentity : UInt16*,   # LPCWSTR optional
    phCryptProv : LibC::SizeT*   # UINT_PTR* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef PeerIdentityGetCryptKeyNative = Int32 Function(Pointer<Utf16>, Pointer<UintPtr>);
typedef PeerIdentityGetCryptKeyDart = int Function(Pointer<Utf16>, Pointer<UintPtr>);
final PeerIdentityGetCryptKey = DynamicLibrary.open('P2P.dll')
    .lookupFunction<PeerIdentityGetCryptKeyNative, PeerIdentityGetCryptKeyDart>('PeerIdentityGetCryptKey');
// pwzIdentity : LPCWSTR optional -> Pointer<Utf16>
// phCryptProv : UINT_PTR* out -> Pointer<UintPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PeerIdentityGetCryptKey(
  pwzIdentity: PWideChar;   // LPCWSTR optional
  phCryptProv: Pointer   // UINT_PTR* out
): Integer; stdcall;
  external 'P2P.dll' name 'PeerIdentityGetCryptKey';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PeerIdentityGetCryptKey"
  c_PeerIdentityGetCryptKey :: CWString -> Ptr CUIntPtr -> IO Int32
-- pwzIdentity : LPCWSTR optional -> CWString
-- phCryptProv : UINT_PTR* out -> Ptr CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let peeridentitygetcryptkey =
  foreign "PeerIdentityGetCryptKey"
    ((ptr uint16_t) @-> (ptr size_t) @-> returning int32_t)
(* pwzIdentity : LPCWSTR optional -> (ptr uint16_t) *)
(* phCryptProv : UINT_PTR* out -> (ptr size_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library p2p (t "P2P.dll"))
(cffi:use-foreign-library p2p)

(cffi:defcfun ("PeerIdentityGetCryptKey" peer-identity-get-crypt-key :convention :stdcall) :int32
  (pwz-identity (:string :encoding :utf-16le))   ; LPCWSTR optional
  (ph-crypt-prov :pointer))   ; UINT_PTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PeerIdentityGetCryptKey = Win32::API::More->new('P2P',
    'int PeerIdentityGetCryptKey(LPCWSTR pwzIdentity, LPVOID phCryptProv)');
# my $ret = $PeerIdentityGetCryptKey->Call($pwzIdentity, $phCryptProv);
# pwzIdentity : LPCWSTR optional -> LPCWSTR
# phCryptProv : UINT_PTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。