Win32 API 日本語リファレンス
ホームSecurity.Cryptography › NCryptQueryProtectionDescriptorName

NCryptQueryProtectionDescriptorName

関数
登録済み保護記述子名から記述子文字列を照会する。
DLLncrypt.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

HRESULT NCryptQueryProtectionDescriptorName(
    LPCWSTR pwszName,
    LPWSTR pwszDescriptorString,   // optional
    UINT_PTR* pcDescriptorString,
    DWORD dwFlags
);

パラメーター

名前方向
pwszNameLPCWSTRin
pwszDescriptorStringLPWSTRoutoptional
pcDescriptorStringUINT_PTR*inout
dwFlagsDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT NCryptQueryProtectionDescriptorName(
    LPCWSTR pwszName,
    LPWSTR pwszDescriptorString,   // optional
    UINT_PTR* pcDescriptorString,
    DWORD dwFlags
);
[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int NCryptQueryProtectionDescriptorName(
    [MarshalAs(UnmanagedType.LPWStr)] string pwszName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pwszDescriptorString,   // LPWSTR optional, out
    ref UIntPtr pcDescriptorString,   // UINT_PTR* in/out
    uint dwFlags   // DWORD
);
<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function NCryptQueryProtectionDescriptorName(
    <MarshalAs(UnmanagedType.LPWStr)> pwszName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pwszDescriptorString As System.Text.StringBuilder,   ' LPWSTR optional, out
    ByRef pcDescriptorString As UIntPtr,   ' UINT_PTR* in/out
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' pwszName : LPCWSTR
' pwszDescriptorString : LPWSTR optional, out
' pcDescriptorString : UINT_PTR* in/out
' dwFlags : DWORD
Declare PtrSafe Function NCryptQueryProtectionDescriptorName Lib "ncrypt" ( _
    ByVal pwszName As LongPtr, _
    ByVal pwszDescriptorString As LongPtr, _
    ByRef pcDescriptorString As LongPtr, _
    ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NCryptQueryProtectionDescriptorName = ctypes.windll.ncrypt.NCryptQueryProtectionDescriptorName
NCryptQueryProtectionDescriptorName.restype = ctypes.c_int
NCryptQueryProtectionDescriptorName.argtypes = [
    wintypes.LPCWSTR,  # pwszName : LPCWSTR
    wintypes.LPWSTR,  # pwszDescriptorString : LPWSTR optional, out
    ctypes.POINTER(ctypes.c_size_t),  # pcDescriptorString : UINT_PTR* in/out
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
	procNCryptQueryProtectionDescriptorName = ncrypt.NewProc("NCryptQueryProtectionDescriptorName")
)

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