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

NCryptCreateProtectionDescriptor

関数
記述子文字列から保護記述子ハンドルを作成する。
DLLncrypt.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

HRESULT NCryptCreateProtectionDescriptor(
    LPCWSTR pwszDescriptorString,
    DWORD dwFlags,
    NCRYPT_DESCRIPTOR_HANDLE* phDescriptor
);

パラメーター

名前方向
pwszDescriptorStringLPCWSTRin
dwFlagsDWORDin
phDescriptorNCRYPT_DESCRIPTOR_HANDLE*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT NCryptCreateProtectionDescriptor(
    LPCWSTR pwszDescriptorString,
    DWORD dwFlags,
    NCRYPT_DESCRIPTOR_HANDLE* phDescriptor
);
[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int NCryptCreateProtectionDescriptor(
    [MarshalAs(UnmanagedType.LPWStr)] string pwszDescriptorString,   // LPCWSTR
    uint dwFlags,   // DWORD
    IntPtr phDescriptor   // NCRYPT_DESCRIPTOR_HANDLE* out
);
<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function NCryptCreateProtectionDescriptor(
    <MarshalAs(UnmanagedType.LPWStr)> pwszDescriptorString As String,   ' LPCWSTR
    dwFlags As UInteger,   ' DWORD
    phDescriptor As IntPtr   ' NCRYPT_DESCRIPTOR_HANDLE* out
) As Integer
End Function
' pwszDescriptorString : LPCWSTR
' dwFlags : DWORD
' phDescriptor : NCRYPT_DESCRIPTOR_HANDLE* out
Declare PtrSafe Function NCryptCreateProtectionDescriptor Lib "ncrypt" ( _
    ByVal pwszDescriptorString As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal phDescriptor As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NCryptCreateProtectionDescriptor = ctypes.windll.ncrypt.NCryptCreateProtectionDescriptor
NCryptCreateProtectionDescriptor.restype = ctypes.c_int
NCryptCreateProtectionDescriptor.argtypes = [
    wintypes.LPCWSTR,  # pwszDescriptorString : LPCWSTR
    wintypes.DWORD,  # dwFlags : DWORD
    ctypes.c_void_p,  # phDescriptor : NCRYPT_DESCRIPTOR_HANDLE* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ncrypt.dll')
NCryptCreateProtectionDescriptor = Fiddle::Function.new(
  lib['NCryptCreateProtectionDescriptor'],
  [
    Fiddle::TYPE_VOIDP,  # pwszDescriptorString : LPCWSTR
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_VOIDP,  # phDescriptor : NCRYPT_DESCRIPTOR_HANDLE* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ncrypt")]
extern "system" {
    fn NCryptCreateProtectionDescriptor(
        pwszDescriptorString: *const u16,  // LPCWSTR
        dwFlags: u32,  // DWORD
        phDescriptor: *mut *mut core::ffi::c_void  // NCRYPT_DESCRIPTOR_HANDLE* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ncrypt.dll")]
public static extern int NCryptCreateProtectionDescriptor([MarshalAs(UnmanagedType.LPWStr)] string pwszDescriptorString, uint dwFlags, IntPtr phDescriptor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_NCryptCreateProtectionDescriptor' -Namespace Win32 -PassThru
# $api::NCryptCreateProtectionDescriptor(pwszDescriptorString, dwFlags, phDescriptor)
#uselib "ncrypt.dll"
#func global NCryptCreateProtectionDescriptor "NCryptCreateProtectionDescriptor" sptr, sptr, sptr
; NCryptCreateProtectionDescriptor pwszDescriptorString, dwFlags, phDescriptor   ; 戻り値は stat
; pwszDescriptorString : LPCWSTR -> "sptr"
; dwFlags : DWORD -> "sptr"
; phDescriptor : NCRYPT_DESCRIPTOR_HANDLE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ncrypt.dll"
#cfunc global NCryptCreateProtectionDescriptor "NCryptCreateProtectionDescriptor" wstr, int, sptr
; res = NCryptCreateProtectionDescriptor(pwszDescriptorString, dwFlags, phDescriptor)
; pwszDescriptorString : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
; phDescriptor : NCRYPT_DESCRIPTOR_HANDLE* out -> "sptr"
; HRESULT NCryptCreateProtectionDescriptor(LPCWSTR pwszDescriptorString, DWORD dwFlags, NCRYPT_DESCRIPTOR_HANDLE* phDescriptor)
#uselib "ncrypt.dll"
#cfunc global NCryptCreateProtectionDescriptor "NCryptCreateProtectionDescriptor" wstr, int, intptr
; res = NCryptCreateProtectionDescriptor(pwszDescriptorString, dwFlags, phDescriptor)
; pwszDescriptorString : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
; phDescriptor : NCRYPT_DESCRIPTOR_HANDLE* out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
	procNCryptCreateProtectionDescriptor = ncrypt.NewProc("NCryptCreateProtectionDescriptor")
)

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