ホーム › Security.Cryptography › NCryptGetProtectionDescriptorInfo
NCryptGetProtectionDescriptorInfo
関数保護記述子ハンドルから情報を取得する。
シグネチャ
// ncrypt.dll
#include <windows.h>
HRESULT NCryptGetProtectionDescriptorInfo(
NCRYPT_DESCRIPTOR_HANDLE hDescriptor,
const NCRYPT_ALLOC_PARA* pMemPara, // optional
DWORD dwInfoType,
void** ppvInfo
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||
|---|---|---|---|---|---|---|---|
| hDescriptor | NCRYPT_DESCRIPTOR_HANDLE | in | NCryptCreateProtectionDescriptor を呼び出して作成した保護記述子ハンドルです。 | ||||
| pMemPara | NCRYPT_ALLOC_PARA* | inoptional | カスタムのメモリ管理関数を指定するために使用できる NCRYPT_ALLOC_PARA 構造体へのポインターです。この引数を NULL に設定した場合、メモリの割り当てには内部的に LocalAlloc 関数が使用され、アプリケーションは ppvInfo パラメーターが指すメモリを解放するために LocalFree を呼び出す必要があります。 | ||||
| dwInfoType | DWORD | in | 記述子の情報を ppvInfo パラメーターにどのように返すかを指定します。次の値を指定できます。
| ||||
| ppvInfo | void** | out | 記述子の情報へのポインターです。 |
戻り値の型: HRESULT
公式ドキュメント
保護記述子のルール文字列を取得します。
戻り値
関数の成否を示すステータスコードを返します。返される可能性があるコードには、以下のものが含まれますが、これらに限定されません。
| 戻り値 | 説明 |
|---|---|
| 関数は成功しました。 | |
| ppvInfo パラメーターを NULL にすることはできません。 | |
| dwInfoType パラメーターにサポートされていない値が指定されました。 | |
| hDescriptor パラメーターで指定されたハンドルが無効です。 |
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// ncrypt.dll
#include <windows.h>
HRESULT NCryptGetProtectionDescriptorInfo(
NCRYPT_DESCRIPTOR_HANDLE hDescriptor,
const NCRYPT_ALLOC_PARA* pMemPara, // optional
DWORD dwInfoType,
void** ppvInfo
);[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int NCryptGetProtectionDescriptorInfo(
IntPtr hDescriptor, // NCRYPT_DESCRIPTOR_HANDLE
IntPtr pMemPara, // NCRYPT_ALLOC_PARA* optional
uint dwInfoType, // DWORD
IntPtr ppvInfo // void** out
);<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function NCryptGetProtectionDescriptorInfo(
hDescriptor As IntPtr, ' NCRYPT_DESCRIPTOR_HANDLE
pMemPara As IntPtr, ' NCRYPT_ALLOC_PARA* optional
dwInfoType As UInteger, ' DWORD
ppvInfo As IntPtr ' void** out
) As Integer
End Function' hDescriptor : NCRYPT_DESCRIPTOR_HANDLE
' pMemPara : NCRYPT_ALLOC_PARA* optional
' dwInfoType : DWORD
' ppvInfo : void** out
Declare PtrSafe Function NCryptGetProtectionDescriptorInfo Lib "ncrypt" ( _
ByVal hDescriptor As LongPtr, _
ByVal pMemPara As LongPtr, _
ByVal dwInfoType As Long, _
ByVal ppvInfo As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
NCryptGetProtectionDescriptorInfo = ctypes.windll.ncrypt.NCryptGetProtectionDescriptorInfo
NCryptGetProtectionDescriptorInfo.restype = ctypes.c_int
NCryptGetProtectionDescriptorInfo.argtypes = [
wintypes.HANDLE, # hDescriptor : NCRYPT_DESCRIPTOR_HANDLE
ctypes.c_void_p, # pMemPara : NCRYPT_ALLOC_PARA* optional
wintypes.DWORD, # dwInfoType : DWORD
ctypes.c_void_p, # ppvInfo : void** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ncrypt.dll')
NCryptGetProtectionDescriptorInfo = Fiddle::Function.new(
lib['NCryptGetProtectionDescriptorInfo'],
[
Fiddle::TYPE_VOIDP, # hDescriptor : NCRYPT_DESCRIPTOR_HANDLE
Fiddle::TYPE_VOIDP, # pMemPara : NCRYPT_ALLOC_PARA* optional
-Fiddle::TYPE_INT, # dwInfoType : DWORD
Fiddle::TYPE_VOIDP, # ppvInfo : void** out
],
Fiddle::TYPE_INT)#[link(name = "ncrypt")]
extern "system" {
fn NCryptGetProtectionDescriptorInfo(
hDescriptor: *mut core::ffi::c_void, // NCRYPT_DESCRIPTOR_HANDLE
pMemPara: *const NCRYPT_ALLOC_PARA, // NCRYPT_ALLOC_PARA* optional
dwInfoType: u32, // DWORD
ppvInfo: *mut *mut () // void** out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ncrypt.dll")]
public static extern int NCryptGetProtectionDescriptorInfo(IntPtr hDescriptor, IntPtr pMemPara, uint dwInfoType, IntPtr ppvInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_NCryptGetProtectionDescriptorInfo' -Namespace Win32 -PassThru
# $api::NCryptGetProtectionDescriptorInfo(hDescriptor, pMemPara, dwInfoType, ppvInfo)#uselib "ncrypt.dll"
#func global NCryptGetProtectionDescriptorInfo "NCryptGetProtectionDescriptorInfo" sptr, sptr, sptr, sptr
; NCryptGetProtectionDescriptorInfo hDescriptor, varptr(pMemPara), dwInfoType, ppvInfo ; 戻り値は stat
; hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> "sptr"
; pMemPara : NCRYPT_ALLOC_PARA* optional -> "sptr"
; dwInfoType : DWORD -> "sptr"
; ppvInfo : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ncrypt.dll" #cfunc global NCryptGetProtectionDescriptorInfo "NCryptGetProtectionDescriptorInfo" sptr, var, int, sptr ; res = NCryptGetProtectionDescriptorInfo(hDescriptor, pMemPara, dwInfoType, ppvInfo) ; hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> "sptr" ; pMemPara : NCRYPT_ALLOC_PARA* optional -> "var" ; dwInfoType : DWORD -> "int" ; ppvInfo : void** out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ncrypt.dll" #cfunc global NCryptGetProtectionDescriptorInfo "NCryptGetProtectionDescriptorInfo" sptr, sptr, int, sptr ; res = NCryptGetProtectionDescriptorInfo(hDescriptor, varptr(pMemPara), dwInfoType, ppvInfo) ; hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> "sptr" ; pMemPara : NCRYPT_ALLOC_PARA* optional -> "sptr" ; dwInfoType : DWORD -> "int" ; ppvInfo : void** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT NCryptGetProtectionDescriptorInfo(NCRYPT_DESCRIPTOR_HANDLE hDescriptor, NCRYPT_ALLOC_PARA* pMemPara, DWORD dwInfoType, void** ppvInfo) #uselib "ncrypt.dll" #cfunc global NCryptGetProtectionDescriptorInfo "NCryptGetProtectionDescriptorInfo" intptr, var, int, intptr ; res = NCryptGetProtectionDescriptorInfo(hDescriptor, pMemPara, dwInfoType, ppvInfo) ; hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> "intptr" ; pMemPara : NCRYPT_ALLOC_PARA* optional -> "var" ; dwInfoType : DWORD -> "int" ; ppvInfo : void** out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT NCryptGetProtectionDescriptorInfo(NCRYPT_DESCRIPTOR_HANDLE hDescriptor, NCRYPT_ALLOC_PARA* pMemPara, DWORD dwInfoType, void** ppvInfo) #uselib "ncrypt.dll" #cfunc global NCryptGetProtectionDescriptorInfo "NCryptGetProtectionDescriptorInfo" intptr, intptr, int, intptr ; res = NCryptGetProtectionDescriptorInfo(hDescriptor, varptr(pMemPara), dwInfoType, ppvInfo) ; hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> "intptr" ; pMemPara : NCRYPT_ALLOC_PARA* optional -> "intptr" ; dwInfoType : DWORD -> "int" ; ppvInfo : void** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
procNCryptGetProtectionDescriptorInfo = ncrypt.NewProc("NCryptGetProtectionDescriptorInfo")
)
// hDescriptor (NCRYPT_DESCRIPTOR_HANDLE), pMemPara (NCRYPT_ALLOC_PARA* optional), dwInfoType (DWORD), ppvInfo (void** out)
r1, _, err := procNCryptGetProtectionDescriptorInfo.Call(
uintptr(hDescriptor),
uintptr(pMemPara),
uintptr(dwInfoType),
uintptr(ppvInfo),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction NCryptGetProtectionDescriptorInfo(
hDescriptor: THandle; // NCRYPT_DESCRIPTOR_HANDLE
pMemPara: Pointer; // NCRYPT_ALLOC_PARA* optional
dwInfoType: DWORD; // DWORD
ppvInfo: Pointer // void** out
): Integer; stdcall;
external 'ncrypt.dll' name 'NCryptGetProtectionDescriptorInfo';result := DllCall("ncrypt\NCryptGetProtectionDescriptorInfo"
, "Ptr", hDescriptor ; NCRYPT_DESCRIPTOR_HANDLE
, "Ptr", pMemPara ; NCRYPT_ALLOC_PARA* optional
, "UInt", dwInfoType ; DWORD
, "Ptr", ppvInfo ; void** out
, "Int") ; return: HRESULT●NCryptGetProtectionDescriptorInfo(hDescriptor, pMemPara, dwInfoType, ppvInfo) = DLL("ncrypt.dll", "int NCryptGetProtectionDescriptorInfo(void*, void*, dword, void*)")
# 呼び出し: NCryptGetProtectionDescriptorInfo(hDescriptor, pMemPara, dwInfoType, ppvInfo)
# hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> "void*"
# pMemPara : NCRYPT_ALLOC_PARA* optional -> "void*"
# dwInfoType : DWORD -> "dword"
# ppvInfo : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ncrypt" fn NCryptGetProtectionDescriptorInfo(
hDescriptor: ?*anyopaque, // NCRYPT_DESCRIPTOR_HANDLE
pMemPara: [*c]NCRYPT_ALLOC_PARA, // NCRYPT_ALLOC_PARA* optional
dwInfoType: u32, // DWORD
ppvInfo: ?*anyopaque // void** out
) callconv(std.os.windows.WINAPI) i32;proc NCryptGetProtectionDescriptorInfo(
hDescriptor: pointer, # NCRYPT_DESCRIPTOR_HANDLE
pMemPara: ptr NCRYPT_ALLOC_PARA, # NCRYPT_ALLOC_PARA* optional
dwInfoType: uint32, # DWORD
ppvInfo: pointer # void** out
): int32 {.importc: "NCryptGetProtectionDescriptorInfo", stdcall, dynlib: "ncrypt.dll".}pragma(lib, "ncrypt");
extern(Windows)
int NCryptGetProtectionDescriptorInfo(
void* hDescriptor, // NCRYPT_DESCRIPTOR_HANDLE
NCRYPT_ALLOC_PARA* pMemPara, // NCRYPT_ALLOC_PARA* optional
uint dwInfoType, // DWORD
void** ppvInfo // void** out
);ccall((:NCryptGetProtectionDescriptorInfo, "ncrypt.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{NCRYPT_ALLOC_PARA}, UInt32, Ptr{Cvoid}),
hDescriptor, pMemPara, dwInfoType, ppvInfo)
# hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> Ptr{Cvoid}
# pMemPara : NCRYPT_ALLOC_PARA* optional -> Ptr{NCRYPT_ALLOC_PARA}
# dwInfoType : DWORD -> UInt32
# ppvInfo : void** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t NCryptGetProtectionDescriptorInfo(
void* hDescriptor,
void* pMemPara,
uint32_t dwInfoType,
void** ppvInfo);
]]
local ncrypt = ffi.load("ncrypt")
-- ncrypt.NCryptGetProtectionDescriptorInfo(hDescriptor, pMemPara, dwInfoType, ppvInfo)
-- hDescriptor : NCRYPT_DESCRIPTOR_HANDLE
-- pMemPara : NCRYPT_ALLOC_PARA* optional
-- dwInfoType : DWORD
-- ppvInfo : void** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ncrypt.dll');
const NCryptGetProtectionDescriptorInfo = lib.func('__stdcall', 'NCryptGetProtectionDescriptorInfo', 'int32_t', ['void *', 'void *', 'uint32_t', 'void *']);
// NCryptGetProtectionDescriptorInfo(hDescriptor, pMemPara, dwInfoType, ppvInfo)
// hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> 'void *'
// pMemPara : NCRYPT_ALLOC_PARA* optional -> 'void *'
// dwInfoType : DWORD -> 'uint32_t'
// ppvInfo : void** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ncrypt.dll", {
NCryptGetProtectionDescriptorInfo: { parameters: ["pointer", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.NCryptGetProtectionDescriptorInfo(hDescriptor, pMemPara, dwInfoType, ppvInfo)
// hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> "pointer"
// pMemPara : NCRYPT_ALLOC_PARA* optional -> "pointer"
// dwInfoType : DWORD -> "u32"
// ppvInfo : void** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t NCryptGetProtectionDescriptorInfo(
void* hDescriptor,
void* pMemPara,
uint32_t dwInfoType,
void** ppvInfo);
C, "ncrypt.dll");
// $ffi->NCryptGetProtectionDescriptorInfo(hDescriptor, pMemPara, dwInfoType, ppvInfo);
// hDescriptor : NCRYPT_DESCRIPTOR_HANDLE
// pMemPara : NCRYPT_ALLOC_PARA* optional
// dwInfoType : DWORD
// ppvInfo : 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 Ncrypt extends StdCallLibrary {
Ncrypt INSTANCE = Native.load("ncrypt", Ncrypt.class);
int NCryptGetProtectionDescriptorInfo(
Pointer hDescriptor, // NCRYPT_DESCRIPTOR_HANDLE
Pointer pMemPara, // NCRYPT_ALLOC_PARA* optional
int dwInfoType, // DWORD
Pointer ppvInfo // void** out
);
}@[Link("ncrypt")]
lib Libncrypt
fun NCryptGetProtectionDescriptorInfo = NCryptGetProtectionDescriptorInfo(
hDescriptor : Void*, # NCRYPT_DESCRIPTOR_HANDLE
pMemPara : NCRYPT_ALLOC_PARA*, # NCRYPT_ALLOC_PARA* optional
dwInfoType : UInt32, # DWORD
ppvInfo : Void** # void** out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NCryptGetProtectionDescriptorInfoNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32, Pointer<Void>);
typedef NCryptGetProtectionDescriptorInfoDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<Void>);
final NCryptGetProtectionDescriptorInfo = DynamicLibrary.open('ncrypt.dll')
.lookupFunction<NCryptGetProtectionDescriptorInfoNative, NCryptGetProtectionDescriptorInfoDart>('NCryptGetProtectionDescriptorInfo');
// hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> Pointer<Void>
// pMemPara : NCRYPT_ALLOC_PARA* optional -> Pointer<Void>
// dwInfoType : DWORD -> Uint32
// ppvInfo : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function NCryptGetProtectionDescriptorInfo(
hDescriptor: THandle; // NCRYPT_DESCRIPTOR_HANDLE
pMemPara: Pointer; // NCRYPT_ALLOC_PARA* optional
dwInfoType: DWORD; // DWORD
ppvInfo: Pointer // void** out
): Integer; stdcall;
external 'ncrypt.dll' name 'NCryptGetProtectionDescriptorInfo';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NCryptGetProtectionDescriptorInfo"
c_NCryptGetProtectionDescriptorInfo :: Ptr () -> Ptr () -> Word32 -> Ptr () -> IO Int32
-- hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> Ptr ()
-- pMemPara : NCRYPT_ALLOC_PARA* optional -> Ptr ()
-- dwInfoType : DWORD -> Word32
-- ppvInfo : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ncryptgetprotectiondescriptorinfo =
foreign "NCryptGetProtectionDescriptorInfo"
((ptr void) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> (ptr void) *)
(* pMemPara : NCRYPT_ALLOC_PARA* optional -> (ptr void) *)
(* dwInfoType : DWORD -> uint32_t *)
(* ppvInfo : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ncrypt (t "ncrypt.dll"))
(cffi:use-foreign-library ncrypt)
(cffi:defcfun ("NCryptGetProtectionDescriptorInfo" ncrypt-get-protection-descriptor-info :convention :stdcall) :int32
(h-descriptor :pointer) ; NCRYPT_DESCRIPTOR_HANDLE
(p-mem-para :pointer) ; NCRYPT_ALLOC_PARA* optional
(dw-info-type :uint32) ; DWORD
(ppv-info :pointer)) ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NCryptGetProtectionDescriptorInfo = Win32::API::More->new('ncrypt',
'int NCryptGetProtectionDescriptorInfo(HANDLE hDescriptor, LPVOID pMemPara, DWORD dwInfoType, LPVOID ppvInfo)');
# my $ret = $NCryptGetProtectionDescriptorInfo->Call($hDescriptor, $pMemPara, $dwInfoType, $ppvInfo);
# hDescriptor : NCRYPT_DESCRIPTOR_HANDLE -> HANDLE
# pMemPara : NCRYPT_ALLOC_PARA* optional -> LPVOID
# dwInfoType : DWORD -> DWORD
# ppvInfo : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f NCryptCreateProtectionDescriptor — 記述子文字列から保護記述子ハンドルを作成する。
使用する型