ホーム › Security.Cryptography › NCryptRegisterProtectionDescriptorName
NCryptRegisterProtectionDescriptorName
関数保護記述子の名前付きルールを登録する。
シグネチャ
// ncrypt.dll
#include <windows.h>
HRESULT NCryptRegisterProtectionDescriptorName(
LPCWSTR pwszName,
LPCWSTR pwszDescriptorString, // optional
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pwszName | LPCWSTR | in |
| pwszDescriptorString | LPCWSTR | inoptional |
| dwFlags | DWORD | in |
戻り値の型: HRESULT
各言語での呼び出し定義
// ncrypt.dll
#include <windows.h>
HRESULT NCryptRegisterProtectionDescriptorName(
LPCWSTR pwszName,
LPCWSTR pwszDescriptorString, // optional
DWORD dwFlags
);[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int NCryptRegisterProtectionDescriptorName(
[MarshalAs(UnmanagedType.LPWStr)] string pwszName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pwszDescriptorString, // LPCWSTR optional
uint dwFlags // DWORD
);<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function NCryptRegisterProtectionDescriptorName(
<MarshalAs(UnmanagedType.LPWStr)> pwszName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pwszDescriptorString As String, ' LPCWSTR optional
dwFlags As UInteger ' DWORD
) As Integer
End Function' pwszName : LPCWSTR
' pwszDescriptorString : LPCWSTR optional
' dwFlags : DWORD
Declare PtrSafe Function NCryptRegisterProtectionDescriptorName Lib "ncrypt" ( _
ByVal pwszName As LongPtr, _
ByVal pwszDescriptorString 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
NCryptRegisterProtectionDescriptorName = ctypes.windll.ncrypt.NCryptRegisterProtectionDescriptorName
NCryptRegisterProtectionDescriptorName.restype = ctypes.c_int
NCryptRegisterProtectionDescriptorName.argtypes = [
wintypes.LPCWSTR, # pwszName : LPCWSTR
wintypes.LPCWSTR, # pwszDescriptorString : LPCWSTR optional
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ncrypt.dll')
NCryptRegisterProtectionDescriptorName = Fiddle::Function.new(
lib['NCryptRegisterProtectionDescriptorName'],
[
Fiddle::TYPE_VOIDP, # pwszName : LPCWSTR
Fiddle::TYPE_VOIDP, # pwszDescriptorString : LPCWSTR optional
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "ncrypt")]
extern "system" {
fn NCryptRegisterProtectionDescriptorName(
pwszName: *const u16, // LPCWSTR
pwszDescriptorString: *const u16, // LPCWSTR optional
dwFlags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ncrypt.dll")]
public static extern int NCryptRegisterProtectionDescriptorName([MarshalAs(UnmanagedType.LPWStr)] string pwszName, [MarshalAs(UnmanagedType.LPWStr)] string pwszDescriptorString, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_NCryptRegisterProtectionDescriptorName' -Namespace Win32 -PassThru
# $api::NCryptRegisterProtectionDescriptorName(pwszName, pwszDescriptorString, dwFlags)#uselib "ncrypt.dll"
#func global NCryptRegisterProtectionDescriptorName "NCryptRegisterProtectionDescriptorName" sptr, sptr, sptr
; NCryptRegisterProtectionDescriptorName pwszName, pwszDescriptorString, dwFlags ; 戻り値は stat
; pwszName : LPCWSTR -> "sptr"
; pwszDescriptorString : LPCWSTR optional -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ncrypt.dll"
#cfunc global NCryptRegisterProtectionDescriptorName "NCryptRegisterProtectionDescriptorName" wstr, wstr, int
; res = NCryptRegisterProtectionDescriptorName(pwszName, pwszDescriptorString, dwFlags)
; pwszName : LPCWSTR -> "wstr"
; pwszDescriptorString : LPCWSTR optional -> "wstr"
; dwFlags : DWORD -> "int"; HRESULT NCryptRegisterProtectionDescriptorName(LPCWSTR pwszName, LPCWSTR pwszDescriptorString, DWORD dwFlags)
#uselib "ncrypt.dll"
#cfunc global NCryptRegisterProtectionDescriptorName "NCryptRegisterProtectionDescriptorName" wstr, wstr, int
; res = NCryptRegisterProtectionDescriptorName(pwszName, pwszDescriptorString, dwFlags)
; pwszName : LPCWSTR -> "wstr"
; pwszDescriptorString : LPCWSTR optional -> "wstr"
; dwFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
procNCryptRegisterProtectionDescriptorName = ncrypt.NewProc("NCryptRegisterProtectionDescriptorName")
)
// pwszName (LPCWSTR), pwszDescriptorString (LPCWSTR optional), dwFlags (DWORD)
r1, _, err := procNCryptRegisterProtectionDescriptorName.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszDescriptorString))),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction NCryptRegisterProtectionDescriptorName(
pwszName: PWideChar; // LPCWSTR
pwszDescriptorString: PWideChar; // LPCWSTR optional
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'ncrypt.dll' name 'NCryptRegisterProtectionDescriptorName';result := DllCall("ncrypt\NCryptRegisterProtectionDescriptorName"
, "WStr", pwszName ; LPCWSTR
, "WStr", pwszDescriptorString ; LPCWSTR optional
, "UInt", dwFlags ; DWORD
, "Int") ; return: HRESULT●NCryptRegisterProtectionDescriptorName(pwszName, pwszDescriptorString, dwFlags) = DLL("ncrypt.dll", "int NCryptRegisterProtectionDescriptorName(char*, char*, dword)")
# 呼び出し: NCryptRegisterProtectionDescriptorName(pwszName, pwszDescriptorString, dwFlags)
# pwszName : LPCWSTR -> "char*"
# pwszDescriptorString : LPCWSTR optional -> "char*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。