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

NCryptStreamOpenToUnprotect

関数
ストリーム形式で保護データを復号するためのハンドルを開く。
DLLncrypt.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

HRESULT NCryptStreamOpenToUnprotect(
    NCRYPT_PROTECT_STREAM_INFO* pStreamInfo,
    DWORD dwFlags,
    HWND hWnd,   // optional
    NCRYPT_STREAM_HANDLE* phStream
);

パラメーター

名前方向
pStreamInfoNCRYPT_PROTECT_STREAM_INFO*in
dwFlagsDWORDin
hWndHWNDinoptional
phStreamNCRYPT_STREAM_HANDLE*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT NCryptStreamOpenToUnprotect(
    NCRYPT_PROTECT_STREAM_INFO* pStreamInfo,
    DWORD dwFlags,
    HWND hWnd,   // optional
    NCRYPT_STREAM_HANDLE* phStream
);
[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int NCryptStreamOpenToUnprotect(
    IntPtr pStreamInfo,   // NCRYPT_PROTECT_STREAM_INFO*
    uint dwFlags,   // DWORD
    IntPtr hWnd,   // HWND optional
    IntPtr phStream   // NCRYPT_STREAM_HANDLE* out
);
<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function NCryptStreamOpenToUnprotect(
    pStreamInfo As IntPtr,   ' NCRYPT_PROTECT_STREAM_INFO*
    dwFlags As UInteger,   ' DWORD
    hWnd As IntPtr,   ' HWND optional
    phStream As IntPtr   ' NCRYPT_STREAM_HANDLE* out
) As Integer
End Function
' pStreamInfo : NCRYPT_PROTECT_STREAM_INFO*
' dwFlags : DWORD
' hWnd : HWND optional
' phStream : NCRYPT_STREAM_HANDLE* out
Declare PtrSafe Function NCryptStreamOpenToUnprotect Lib "ncrypt" ( _
    ByVal pStreamInfo As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal hWnd As LongPtr, _
    ByVal phStream As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NCryptStreamOpenToUnprotect = ctypes.windll.ncrypt.NCryptStreamOpenToUnprotect
NCryptStreamOpenToUnprotect.restype = ctypes.c_int
NCryptStreamOpenToUnprotect.argtypes = [
    ctypes.c_void_p,  # pStreamInfo : NCRYPT_PROTECT_STREAM_INFO*
    wintypes.DWORD,  # dwFlags : DWORD
    wintypes.HANDLE,  # hWnd : HWND optional
    ctypes.c_void_p,  # phStream : NCRYPT_STREAM_HANDLE* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ncrypt.dll')
NCryptStreamOpenToUnprotect = Fiddle::Function.new(
  lib['NCryptStreamOpenToUnprotect'],
  [
    Fiddle::TYPE_VOIDP,  # pStreamInfo : NCRYPT_PROTECT_STREAM_INFO*
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_VOIDP,  # hWnd : HWND optional
    Fiddle::TYPE_VOIDP,  # phStream : NCRYPT_STREAM_HANDLE* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ncrypt")]
extern "system" {
    fn NCryptStreamOpenToUnprotect(
        pStreamInfo: *mut NCRYPT_PROTECT_STREAM_INFO,  // NCRYPT_PROTECT_STREAM_INFO*
        dwFlags: u32,  // DWORD
        hWnd: *mut core::ffi::c_void,  // HWND optional
        phStream: *mut *mut core::ffi::c_void  // NCRYPT_STREAM_HANDLE* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ncrypt.dll")]
public static extern int NCryptStreamOpenToUnprotect(IntPtr pStreamInfo, uint dwFlags, IntPtr hWnd, IntPtr phStream);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_NCryptStreamOpenToUnprotect' -Namespace Win32 -PassThru
# $api::NCryptStreamOpenToUnprotect(pStreamInfo, dwFlags, hWnd, phStream)
#uselib "ncrypt.dll"
#func global NCryptStreamOpenToUnprotect "NCryptStreamOpenToUnprotect" sptr, sptr, sptr, sptr
; NCryptStreamOpenToUnprotect varptr(pStreamInfo), dwFlags, hWnd, phStream   ; 戻り値は stat
; pStreamInfo : NCRYPT_PROTECT_STREAM_INFO* -> "sptr"
; dwFlags : DWORD -> "sptr"
; hWnd : HWND optional -> "sptr"
; phStream : NCRYPT_STREAM_HANDLE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ncrypt.dll"
#cfunc global NCryptStreamOpenToUnprotect "NCryptStreamOpenToUnprotect" var, int, sptr, sptr
; res = NCryptStreamOpenToUnprotect(pStreamInfo, dwFlags, hWnd, phStream)
; pStreamInfo : NCRYPT_PROTECT_STREAM_INFO* -> "var"
; dwFlags : DWORD -> "int"
; hWnd : HWND optional -> "sptr"
; phStream : NCRYPT_STREAM_HANDLE* out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT NCryptStreamOpenToUnprotect(NCRYPT_PROTECT_STREAM_INFO* pStreamInfo, DWORD dwFlags, HWND hWnd, NCRYPT_STREAM_HANDLE* phStream)
#uselib "ncrypt.dll"
#cfunc global NCryptStreamOpenToUnprotect "NCryptStreamOpenToUnprotect" var, int, intptr, intptr
; res = NCryptStreamOpenToUnprotect(pStreamInfo, dwFlags, hWnd, phStream)
; pStreamInfo : NCRYPT_PROTECT_STREAM_INFO* -> "var"
; dwFlags : DWORD -> "int"
; hWnd : HWND optional -> "intptr"
; phStream : NCRYPT_STREAM_HANDLE* out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
	procNCryptStreamOpenToUnprotect = ncrypt.NewProc("NCryptStreamOpenToUnprotect")
)

// pStreamInfo (NCRYPT_PROTECT_STREAM_INFO*), dwFlags (DWORD), hWnd (HWND optional), phStream (NCRYPT_STREAM_HANDLE* out)
r1, _, err := procNCryptStreamOpenToUnprotect.Call(
	uintptr(pStreamInfo),
	uintptr(dwFlags),
	uintptr(hWnd),
	uintptr(phStream),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function NCryptStreamOpenToUnprotect(
  pStreamInfo: Pointer;   // NCRYPT_PROTECT_STREAM_INFO*
  dwFlags: DWORD;   // DWORD
  hWnd: THandle;   // HWND optional
  phStream: Pointer   // NCRYPT_STREAM_HANDLE* out
): Integer; stdcall;
  external 'ncrypt.dll' name 'NCryptStreamOpenToUnprotect';
result := DllCall("ncrypt\NCryptStreamOpenToUnprotect"
    , "Ptr", pStreamInfo   ; NCRYPT_PROTECT_STREAM_INFO*
    , "UInt", dwFlags   ; DWORD
    , "Ptr", hWnd   ; HWND optional
    , "Ptr", phStream   ; NCRYPT_STREAM_HANDLE* out
    , "Int")   ; return: HRESULT
●NCryptStreamOpenToUnprotect(pStreamInfo, dwFlags, hWnd, phStream) = DLL("ncrypt.dll", "int NCryptStreamOpenToUnprotect(void*, dword, void*, void*)")
# 呼び出し: NCryptStreamOpenToUnprotect(pStreamInfo, dwFlags, hWnd, phStream)
# pStreamInfo : NCRYPT_PROTECT_STREAM_INFO* -> "void*"
# dwFlags : DWORD -> "dword"
# hWnd : HWND optional -> "void*"
# phStream : NCRYPT_STREAM_HANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。