ホーム › NetworkManagement.P2P › PeerIdentityCreate
PeerIdentityCreate
関数新しいピアアイデンティティを作成する。
シグネチャ
// P2P.dll
#include <windows.h>
HRESULT PeerIdentityCreate(
LPCWSTR pwzClassifier, // optional
LPCWSTR pwzFriendlyName, // optional
UINT_PTR hCryptProv, // optional
LPWSTR* ppwzIdentity
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pwzClassifier | LPCWSTR | inoptional | ピア名生成に用いる分類子文字列へのポインター。NULL可。 |
| pwzFriendlyName | LPCWSTR | inoptional | 識別子に付与する表示用フレンドリ名を示す文字列へのポインター。 |
| hCryptProv | UINT_PTR | inoptional | 使用する暗号化プロバイダーのハンドル。0で既定のキーペアを生成する。 |
| ppwzIdentity | LPWSTR* | out | 作成されたピア識別子を受け取る出力。PeerFreeDataで解放する。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// P2P.dll
#include <windows.h>
HRESULT PeerIdentityCreate(
LPCWSTR pwzClassifier, // optional
LPCWSTR pwzFriendlyName, // optional
UINT_PTR hCryptProv, // optional
LPWSTR* ppwzIdentity
);[DllImport("P2P.dll", ExactSpelling = true)]
static extern int PeerIdentityCreate(
[MarshalAs(UnmanagedType.LPWStr)] string pwzClassifier, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pwzFriendlyName, // LPCWSTR optional
UIntPtr hCryptProv, // UINT_PTR optional
IntPtr ppwzIdentity // LPWSTR* out
);<DllImport("P2P.dll", ExactSpelling:=True)>
Public Shared Function PeerIdentityCreate(
<MarshalAs(UnmanagedType.LPWStr)> pwzClassifier As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pwzFriendlyName As String, ' LPCWSTR optional
hCryptProv As UIntPtr, ' UINT_PTR optional
ppwzIdentity As IntPtr ' LPWSTR* out
) As Integer
End Function' pwzClassifier : LPCWSTR optional
' pwzFriendlyName : LPCWSTR optional
' hCryptProv : UINT_PTR optional
' ppwzIdentity : LPWSTR* out
Declare PtrSafe Function PeerIdentityCreate Lib "p2p" ( _
ByVal pwzClassifier As LongPtr, _
ByVal pwzFriendlyName As LongPtr, _
ByVal hCryptProv As LongPtr, _
ByVal ppwzIdentity As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PeerIdentityCreate = ctypes.windll.p2p.PeerIdentityCreate
PeerIdentityCreate.restype = ctypes.c_int
PeerIdentityCreate.argtypes = [
wintypes.LPCWSTR, # pwzClassifier : LPCWSTR optional
wintypes.LPCWSTR, # pwzFriendlyName : LPCWSTR optional
ctypes.c_size_t, # hCryptProv : UINT_PTR optional
ctypes.c_void_p, # ppwzIdentity : LPWSTR* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('P2P.dll')
PeerIdentityCreate = Fiddle::Function.new(
lib['PeerIdentityCreate'],
[
Fiddle::TYPE_VOIDP, # pwzClassifier : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pwzFriendlyName : LPCWSTR optional
Fiddle::TYPE_UINTPTR_T, # hCryptProv : UINT_PTR optional
Fiddle::TYPE_VOIDP, # ppwzIdentity : LPWSTR* out
],
Fiddle::TYPE_INT)#[link(name = "p2p")]
extern "system" {
fn PeerIdentityCreate(
pwzClassifier: *const u16, // LPCWSTR optional
pwzFriendlyName: *const u16, // LPCWSTR optional
hCryptProv: usize, // UINT_PTR optional
ppwzIdentity: *mut *mut u16 // LPWSTR* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("P2P.dll")]
public static extern int PeerIdentityCreate([MarshalAs(UnmanagedType.LPWStr)] string pwzClassifier, [MarshalAs(UnmanagedType.LPWStr)] string pwzFriendlyName, UIntPtr hCryptProv, IntPtr ppwzIdentity);
"@
$api = Add-Type -MemberDefinition $sig -Name 'P2P_PeerIdentityCreate' -Namespace Win32 -PassThru
# $api::PeerIdentityCreate(pwzClassifier, pwzFriendlyName, hCryptProv, ppwzIdentity)#uselib "P2P.dll"
#func global PeerIdentityCreate "PeerIdentityCreate" sptr, sptr, sptr, sptr
; PeerIdentityCreate pwzClassifier, pwzFriendlyName, hCryptProv, varptr(ppwzIdentity) ; 戻り値は stat
; pwzClassifier : LPCWSTR optional -> "sptr"
; pwzFriendlyName : LPCWSTR optional -> "sptr"
; hCryptProv : UINT_PTR optional -> "sptr"
; ppwzIdentity : LPWSTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "P2P.dll" #cfunc global PeerIdentityCreate "PeerIdentityCreate" wstr, wstr, sptr, var ; res = PeerIdentityCreate(pwzClassifier, pwzFriendlyName, hCryptProv, ppwzIdentity) ; pwzClassifier : LPCWSTR optional -> "wstr" ; pwzFriendlyName : LPCWSTR optional -> "wstr" ; hCryptProv : UINT_PTR optional -> "sptr" ; ppwzIdentity : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "P2P.dll" #cfunc global PeerIdentityCreate "PeerIdentityCreate" wstr, wstr, sptr, sptr ; res = PeerIdentityCreate(pwzClassifier, pwzFriendlyName, hCryptProv, varptr(ppwzIdentity)) ; pwzClassifier : LPCWSTR optional -> "wstr" ; pwzFriendlyName : LPCWSTR optional -> "wstr" ; hCryptProv : UINT_PTR optional -> "sptr" ; ppwzIdentity : LPWSTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT PeerIdentityCreate(LPCWSTR pwzClassifier, LPCWSTR pwzFriendlyName, UINT_PTR hCryptProv, LPWSTR* ppwzIdentity) #uselib "P2P.dll" #cfunc global PeerIdentityCreate "PeerIdentityCreate" wstr, wstr, intptr, var ; res = PeerIdentityCreate(pwzClassifier, pwzFriendlyName, hCryptProv, ppwzIdentity) ; pwzClassifier : LPCWSTR optional -> "wstr" ; pwzFriendlyName : LPCWSTR optional -> "wstr" ; hCryptProv : UINT_PTR optional -> "intptr" ; ppwzIdentity : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT PeerIdentityCreate(LPCWSTR pwzClassifier, LPCWSTR pwzFriendlyName, UINT_PTR hCryptProv, LPWSTR* ppwzIdentity) #uselib "P2P.dll" #cfunc global PeerIdentityCreate "PeerIdentityCreate" wstr, wstr, intptr, intptr ; res = PeerIdentityCreate(pwzClassifier, pwzFriendlyName, hCryptProv, varptr(ppwzIdentity)) ; pwzClassifier : LPCWSTR optional -> "wstr" ; pwzFriendlyName : LPCWSTR optional -> "wstr" ; hCryptProv : UINT_PTR optional -> "intptr" ; ppwzIdentity : LPWSTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
p2p = windows.NewLazySystemDLL("P2P.dll")
procPeerIdentityCreate = p2p.NewProc("PeerIdentityCreate")
)
// pwzClassifier (LPCWSTR optional), pwzFriendlyName (LPCWSTR optional), hCryptProv (UINT_PTR optional), ppwzIdentity (LPWSTR* out)
r1, _, err := procPeerIdentityCreate.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwzClassifier))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwzFriendlyName))),
uintptr(hCryptProv),
uintptr(ppwzIdentity),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction PeerIdentityCreate(
pwzClassifier: PWideChar; // LPCWSTR optional
pwzFriendlyName: PWideChar; // LPCWSTR optional
hCryptProv: NativeUInt; // UINT_PTR optional
ppwzIdentity: PPWideChar // LPWSTR* out
): Integer; stdcall;
external 'P2P.dll' name 'PeerIdentityCreate';result := DllCall("P2P\PeerIdentityCreate"
, "WStr", pwzClassifier ; LPCWSTR optional
, "WStr", pwzFriendlyName ; LPCWSTR optional
, "UPtr", hCryptProv ; UINT_PTR optional
, "Ptr", ppwzIdentity ; LPWSTR* out
, "Int") ; return: HRESULT●PeerIdentityCreate(pwzClassifier, pwzFriendlyName, hCryptProv, ppwzIdentity) = DLL("P2P.dll", "int PeerIdentityCreate(char*, char*, int, void*)")
# 呼び出し: PeerIdentityCreate(pwzClassifier, pwzFriendlyName, hCryptProv, ppwzIdentity)
# pwzClassifier : LPCWSTR optional -> "char*"
# pwzFriendlyName : LPCWSTR optional -> "char*"
# hCryptProv : UINT_PTR optional -> "int"
# ppwzIdentity : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "p2p" fn PeerIdentityCreate(
pwzClassifier: [*c]const u16, // LPCWSTR optional
pwzFriendlyName: [*c]const u16, // LPCWSTR optional
hCryptProv: usize, // UINT_PTR optional
ppwzIdentity: [*c][*c]u16 // LPWSTR* out
) callconv(std.os.windows.WINAPI) i32;proc PeerIdentityCreate(
pwzClassifier: WideCString, # LPCWSTR optional
pwzFriendlyName: WideCString, # LPCWSTR optional
hCryptProv: uint, # UINT_PTR optional
ppwzIdentity: ptr WideCString # LPWSTR* out
): int32 {.importc: "PeerIdentityCreate", stdcall, dynlib: "P2P.dll".}pragma(lib, "p2p");
extern(Windows)
int PeerIdentityCreate(
const(wchar)* pwzClassifier, // LPCWSTR optional
const(wchar)* pwzFriendlyName, // LPCWSTR optional
size_t hCryptProv, // UINT_PTR optional
wchar** ppwzIdentity // LPWSTR* out
);ccall((:PeerIdentityCreate, "P2P.dll"), stdcall, Int32,
(Cwstring, Cwstring, Csize_t, Ptr{Ptr{UInt16}}),
pwzClassifier, pwzFriendlyName, hCryptProv, ppwzIdentity)
# pwzClassifier : LPCWSTR optional -> Cwstring
# pwzFriendlyName : LPCWSTR optional -> Cwstring
# hCryptProv : UINT_PTR optional -> Csize_t
# ppwzIdentity : LPWSTR* out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PeerIdentityCreate(
const uint16_t* pwzClassifier,
const uint16_t* pwzFriendlyName,
uintptr_t hCryptProv,
uint16_t** ppwzIdentity);
]]
local p2p = ffi.load("p2p")
-- p2p.PeerIdentityCreate(pwzClassifier, pwzFriendlyName, hCryptProv, ppwzIdentity)
-- pwzClassifier : LPCWSTR optional
-- pwzFriendlyName : LPCWSTR optional
-- hCryptProv : UINT_PTR optional
-- ppwzIdentity : LPWSTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('P2P.dll');
const PeerIdentityCreate = lib.func('__stdcall', 'PeerIdentityCreate', 'int32_t', ['str16', 'str16', 'uintptr_t', 'void *']);
// PeerIdentityCreate(pwzClassifier, pwzFriendlyName, hCryptProv, ppwzIdentity)
// pwzClassifier : LPCWSTR optional -> 'str16'
// pwzFriendlyName : LPCWSTR optional -> 'str16'
// hCryptProv : UINT_PTR optional -> 'uintptr_t'
// ppwzIdentity : LPWSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("P2P.dll", {
PeerIdentityCreate: { parameters: ["buffer", "buffer", "usize", "pointer"], result: "i32" },
});
// lib.symbols.PeerIdentityCreate(pwzClassifier, pwzFriendlyName, hCryptProv, ppwzIdentity)
// pwzClassifier : LPCWSTR optional -> "buffer"
// pwzFriendlyName : LPCWSTR optional -> "buffer"
// hCryptProv : UINT_PTR optional -> "usize"
// ppwzIdentity : LPWSTR* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PeerIdentityCreate(
const uint16_t* pwzClassifier,
const uint16_t* pwzFriendlyName,
size_t hCryptProv,
uint16_t** ppwzIdentity);
C, "P2P.dll");
// $ffi->PeerIdentityCreate(pwzClassifier, pwzFriendlyName, hCryptProv, ppwzIdentity);
// pwzClassifier : LPCWSTR optional
// pwzFriendlyName : LPCWSTR optional
// hCryptProv : UINT_PTR optional
// ppwzIdentity : LPWSTR* 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 PeerIdentityCreate(
WString pwzClassifier, // LPCWSTR optional
WString pwzFriendlyName, // LPCWSTR optional
long hCryptProv, // UINT_PTR optional
PointerByReference ppwzIdentity // LPWSTR* out
);
}@[Link("p2p")]
lib LibP2P
fun PeerIdentityCreate = PeerIdentityCreate(
pwzClassifier : UInt16*, # LPCWSTR optional
pwzFriendlyName : UInt16*, # LPCWSTR optional
hCryptProv : LibC::SizeT, # UINT_PTR optional
ppwzIdentity : UInt16** # LPWSTR* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PeerIdentityCreateNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, UintPtr, Pointer<Pointer<Utf16>>);
typedef PeerIdentityCreateDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Pointer<Utf16>>);
final PeerIdentityCreate = DynamicLibrary.open('P2P.dll')
.lookupFunction<PeerIdentityCreateNative, PeerIdentityCreateDart>('PeerIdentityCreate');
// pwzClassifier : LPCWSTR optional -> Pointer<Utf16>
// pwzFriendlyName : LPCWSTR optional -> Pointer<Utf16>
// hCryptProv : UINT_PTR optional -> UintPtr
// ppwzIdentity : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PeerIdentityCreate(
pwzClassifier: PWideChar; // LPCWSTR optional
pwzFriendlyName: PWideChar; // LPCWSTR optional
hCryptProv: NativeUInt; // UINT_PTR optional
ppwzIdentity: PPWideChar // LPWSTR* out
): Integer; stdcall;
external 'P2P.dll' name 'PeerIdentityCreate';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PeerIdentityCreate"
c_PeerIdentityCreate :: CWString -> CWString -> CUIntPtr -> Ptr CWString -> IO Int32
-- pwzClassifier : LPCWSTR optional -> CWString
-- pwzFriendlyName : LPCWSTR optional -> CWString
-- hCryptProv : UINT_PTR optional -> CUIntPtr
-- ppwzIdentity : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let peeridentitycreate =
foreign "PeerIdentityCreate"
((ptr uint16_t) @-> (ptr uint16_t) @-> size_t @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* pwzClassifier : LPCWSTR optional -> (ptr uint16_t) *)
(* pwzFriendlyName : LPCWSTR optional -> (ptr uint16_t) *)
(* hCryptProv : UINT_PTR optional -> size_t *)
(* ppwzIdentity : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library p2p (t "P2P.dll"))
(cffi:use-foreign-library p2p)
(cffi:defcfun ("PeerIdentityCreate" peer-identity-create :convention :stdcall) :int32
(pwz-classifier (:string :encoding :utf-16le)) ; LPCWSTR optional
(pwz-friendly-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(h-crypt-prov :uint64) ; UINT_PTR optional
(ppwz-identity :pointer)) ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PeerIdentityCreate = Win32::API::More->new('P2P',
'int PeerIdentityCreate(LPCWSTR pwzClassifier, LPCWSTR pwzFriendlyName, WPARAM hCryptProv, LPVOID ppwzIdentity)');
# my $ret = $PeerIdentityCreate->Call($pwzClassifier, $pwzFriendlyName, $hCryptProv, $ppwzIdentity);
# pwzClassifier : LPCWSTR optional -> LPCWSTR
# pwzFriendlyName : LPCWSTR optional -> LPCWSTR
# hCryptProv : UINT_PTR optional -> WPARAM
# ppwzIdentity : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。