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

NCryptIsAlgSupported

関数
指定アルゴリズムがプロバイダーでサポートされるか判定する。
DLLncrypt.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT NCryptIsAlgSupported(
    NCRYPT_PROV_HANDLE hProvider,
    LPCWSTR pszAlgId,
    DWORD dwFlags
);

パラメーター

名前方向
hProviderNCRYPT_PROV_HANDLEin
pszAlgIdLPCWSTRin
dwFlagsDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT NCryptIsAlgSupported(
    NCRYPT_PROV_HANDLE hProvider,
    LPCWSTR pszAlgId,
    DWORD dwFlags
);
[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int NCryptIsAlgSupported(
    UIntPtr hProvider,   // NCRYPT_PROV_HANDLE
    [MarshalAs(UnmanagedType.LPWStr)] string pszAlgId,   // LPCWSTR
    uint dwFlags   // DWORD
);
<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function NCryptIsAlgSupported(
    hProvider As UIntPtr,   ' NCRYPT_PROV_HANDLE
    <MarshalAs(UnmanagedType.LPWStr)> pszAlgId As String,   ' LPCWSTR
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' hProvider : NCRYPT_PROV_HANDLE
' pszAlgId : LPCWSTR
' dwFlags : DWORD
Declare PtrSafe Function NCryptIsAlgSupported Lib "ncrypt" ( _
    ByVal hProvider As LongPtr, _
    ByVal pszAlgId 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

NCryptIsAlgSupported = ctypes.windll.ncrypt.NCryptIsAlgSupported
NCryptIsAlgSupported.restype = ctypes.c_int
NCryptIsAlgSupported.argtypes = [
    ctypes.c_size_t,  # hProvider : NCRYPT_PROV_HANDLE
    wintypes.LPCWSTR,  # pszAlgId : LPCWSTR
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
	procNCryptIsAlgSupported = ncrypt.NewProc("NCryptIsAlgSupported")
)

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