ホーム › Security.Cryptography › NCryptStreamClose
NCryptStreamClose
関数保護/復号ストリームのハンドルを閉じる。
シグネチャ
// ncrypt.dll
#include <windows.h>
HRESULT NCryptStreamClose(
NCRYPT_STREAM_HANDLE hStream
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hStream | NCRYPT_STREAM_HANDLE | in | NCryptStreamOpenToProtect または NCryptStreamOpenToUnprotect によって返されたデータストリームハンドル。 |
戻り値の型: HRESULT
公式ドキュメント
NCryptStreamOpenToProtect 関数または NCryptStreamOpenToUnprotect 関数を使用して開いたデータ保護ストリームオブジェクトを閉じます。
戻り値
関数の成功または失敗を示すステータスコードを返します。返される可能性のあるコードには、以下のものが含まれますが、これらに限定されません。
| 戻り値コード | 説明 |
|---|---|
| 関数は成功しました。 | |
| hStream パラメーターで指定されたハンドルが無効です。 |
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// ncrypt.dll
#include <windows.h>
HRESULT NCryptStreamClose(
NCRYPT_STREAM_HANDLE hStream
);[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int NCryptStreamClose(
IntPtr hStream // NCRYPT_STREAM_HANDLE
);<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function NCryptStreamClose(
hStream As IntPtr ' NCRYPT_STREAM_HANDLE
) As Integer
End Function' hStream : NCRYPT_STREAM_HANDLE
Declare PtrSafe Function NCryptStreamClose Lib "ncrypt" ( _
ByVal hStream As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
NCryptStreamClose = ctypes.windll.ncrypt.NCryptStreamClose
NCryptStreamClose.restype = ctypes.c_int
NCryptStreamClose.argtypes = [
wintypes.HANDLE, # hStream : NCRYPT_STREAM_HANDLE
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ncrypt.dll')
NCryptStreamClose = Fiddle::Function.new(
lib['NCryptStreamClose'],
[
Fiddle::TYPE_VOIDP, # hStream : NCRYPT_STREAM_HANDLE
],
Fiddle::TYPE_INT)#[link(name = "ncrypt")]
extern "system" {
fn NCryptStreamClose(
hStream: *mut core::ffi::c_void // NCRYPT_STREAM_HANDLE
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ncrypt.dll")]
public static extern int NCryptStreamClose(IntPtr hStream);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_NCryptStreamClose' -Namespace Win32 -PassThru
# $api::NCryptStreamClose(hStream)#uselib "ncrypt.dll"
#func global NCryptStreamClose "NCryptStreamClose" sptr
; NCryptStreamClose hStream ; 戻り値は stat
; hStream : NCRYPT_STREAM_HANDLE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ncrypt.dll"
#cfunc global NCryptStreamClose "NCryptStreamClose" sptr
; res = NCryptStreamClose(hStream)
; hStream : NCRYPT_STREAM_HANDLE -> "sptr"; HRESULT NCryptStreamClose(NCRYPT_STREAM_HANDLE hStream)
#uselib "ncrypt.dll"
#cfunc global NCryptStreamClose "NCryptStreamClose" intptr
; res = NCryptStreamClose(hStream)
; hStream : NCRYPT_STREAM_HANDLE -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
procNCryptStreamClose = ncrypt.NewProc("NCryptStreamClose")
)
// hStream (NCRYPT_STREAM_HANDLE)
r1, _, err := procNCryptStreamClose.Call(
uintptr(hStream),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction NCryptStreamClose(
hStream: THandle // NCRYPT_STREAM_HANDLE
): Integer; stdcall;
external 'ncrypt.dll' name 'NCryptStreamClose';result := DllCall("ncrypt\NCryptStreamClose"
, "Ptr", hStream ; NCRYPT_STREAM_HANDLE
, "Int") ; return: HRESULT●NCryptStreamClose(hStream) = DLL("ncrypt.dll", "int NCryptStreamClose(void*)")
# 呼び出し: NCryptStreamClose(hStream)
# hStream : NCRYPT_STREAM_HANDLE -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ncrypt" fn NCryptStreamClose(
hStream: ?*anyopaque // NCRYPT_STREAM_HANDLE
) callconv(std.os.windows.WINAPI) i32;proc NCryptStreamClose(
hStream: pointer # NCRYPT_STREAM_HANDLE
): int32 {.importc: "NCryptStreamClose", stdcall, dynlib: "ncrypt.dll".}pragma(lib, "ncrypt");
extern(Windows)
int NCryptStreamClose(
void* hStream // NCRYPT_STREAM_HANDLE
);ccall((:NCryptStreamClose, "ncrypt.dll"), stdcall, Int32,
(Ptr{Cvoid},),
hStream)
# hStream : NCRYPT_STREAM_HANDLE -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t NCryptStreamClose(
void* hStream);
]]
local ncrypt = ffi.load("ncrypt")
-- ncrypt.NCryptStreamClose(hStream)
-- hStream : NCRYPT_STREAM_HANDLE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ncrypt.dll');
const NCryptStreamClose = lib.func('__stdcall', 'NCryptStreamClose', 'int32_t', ['void *']);
// NCryptStreamClose(hStream)
// hStream : NCRYPT_STREAM_HANDLE -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ncrypt.dll", {
NCryptStreamClose: { parameters: ["pointer"], result: "i32" },
});
// lib.symbols.NCryptStreamClose(hStream)
// hStream : NCRYPT_STREAM_HANDLE -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t NCryptStreamClose(
void* hStream);
C, "ncrypt.dll");
// $ffi->NCryptStreamClose(hStream);
// hStream : NCRYPT_STREAM_HANDLE
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Ncrypt extends StdCallLibrary {
Ncrypt INSTANCE = Native.load("ncrypt", Ncrypt.class);
int NCryptStreamClose(
Pointer hStream // NCRYPT_STREAM_HANDLE
);
}@[Link("ncrypt")]
lib Libncrypt
fun NCryptStreamClose = NCryptStreamClose(
hStream : Void* # NCRYPT_STREAM_HANDLE
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NCryptStreamCloseNative = Int32 Function(Pointer<Void>);
typedef NCryptStreamCloseDart = int Function(Pointer<Void>);
final NCryptStreamClose = DynamicLibrary.open('ncrypt.dll')
.lookupFunction<NCryptStreamCloseNative, NCryptStreamCloseDart>('NCryptStreamClose');
// hStream : NCRYPT_STREAM_HANDLE -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function NCryptStreamClose(
hStream: THandle // NCRYPT_STREAM_HANDLE
): Integer; stdcall;
external 'ncrypt.dll' name 'NCryptStreamClose';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NCryptStreamClose"
c_NCryptStreamClose :: Ptr () -> IO Int32
-- hStream : NCRYPT_STREAM_HANDLE -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ncryptstreamclose =
foreign "NCryptStreamClose"
((ptr void) @-> returning int32_t)
(* hStream : NCRYPT_STREAM_HANDLE -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ncrypt (t "ncrypt.dll"))
(cffi:use-foreign-library ncrypt)
(cffi:defcfun ("NCryptStreamClose" ncrypt-stream-close :convention :stdcall) :int32
(h-stream :pointer)) ; NCRYPT_STREAM_HANDLE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NCryptStreamClose = Win32::API::More->new('ncrypt',
'int NCryptStreamClose(HANDLE hStream)');
# my $ret = $NCryptStreamClose->Call($hStream);
# hStream : NCRYPT_STREAM_HANDLE -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f NCryptStreamOpenToProtect — ストリーム形式でデータを保護するためのハンドルを開く。
- f NCryptStreamOpenToUnprotect — ストリーム形式で保護データを復号するためのハンドルを開く。
- f NCryptStreamUpdate — 保護/復号ストリームにデータを順次入力して処理する。