Win32 API 日本語リファレンス
ホーム › Storage.CloudFilters › CfGetWin32HandleFromProtectedHandle

CfGetWin32HandleFromProtectedHandle

関数
保護されたハンドルから通常のWin32ハンドルを取得する。
DLLcldapi.dll呼出規約winapi対応OSWindows 10 以降

シグネチャ

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

HANDLE CfGetWin32HandleFromProtectedHandle(
    HANDLE ProtectedHandle
);

パラメーター

名前型方向説明
ProtectedHandleHANDLEin変換対象の保護されたハンドル。

戻り値の型: HANDLE

公式ドキュメント

保護されたハンドルを Win32 ハンドルに変換し、ハンドルベースのすべての Win32 API で使用できるようにします。

戻り値

対応する Win32 ハンドル。

解説(Remarks)

呼び出し元は、この呼び出しの前に CfReferenceProtectedHandle を使用して保護されたハンドルへの参照を取得しておく必要があります。これにより、Win32 ハンドルの使用が追跡され、その Win32 ハンドルを使用する Win32 API 呼び出しが oplock 解除通知の確認応答と同期されます。

呼び出し元は、Win32 ハンドルの使用を終えた後、CfReleaseProtectedHandle を使用して保護されたハンドルへの参照を解放する必要があります。

いかなる場合でも、返された Win32 ハンドルを CfCloseHandle で閉じてはいけません。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

HANDLE CfGetWin32HandleFromProtectedHandle(
    HANDLE ProtectedHandle
);
[DllImport("cldapi.dll", ExactSpelling = true)]
static extern IntPtr CfGetWin32HandleFromProtectedHandle(
    IntPtr ProtectedHandle   // HANDLE
);
<DllImport("cldapi.dll", ExactSpelling:=True)>
Public Shared Function CfGetWin32HandleFromProtectedHandle(
    ProtectedHandle As IntPtr   ' HANDLE
) As IntPtr
End Function
' ProtectedHandle : HANDLE
Declare PtrSafe Function CfGetWin32HandleFromProtectedHandle Lib "cldapi" ( _
    ByVal ProtectedHandle As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CfGetWin32HandleFromProtectedHandle = ctypes.windll.cldapi.CfGetWin32HandleFromProtectedHandle
CfGetWin32HandleFromProtectedHandle.restype = ctypes.c_void_p
CfGetWin32HandleFromProtectedHandle.argtypes = [
    wintypes.HANDLE,  # ProtectedHandle : HANDLE
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('cldapi.dll')
CfGetWin32HandleFromProtectedHandle = Fiddle::Function.new(
  lib['CfGetWin32HandleFromProtectedHandle'],
  [
    Fiddle::TYPE_VOIDP,  # ProtectedHandle : HANDLE
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "cldapi")]
extern "system" {
    fn CfGetWin32HandleFromProtectedHandle(
        ProtectedHandle: *mut core::ffi::c_void  // HANDLE
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("cldapi.dll")]
public static extern IntPtr CfGetWin32HandleFromProtectedHandle(IntPtr ProtectedHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'cldapi_CfGetWin32HandleFromProtectedHandle' -Namespace Win32 -PassThru
# $api::CfGetWin32HandleFromProtectedHandle(ProtectedHandle)
#uselib "cldapi.dll"
#func global CfGetWin32HandleFromProtectedHandle "CfGetWin32HandleFromProtectedHandle" sptr
; CfGetWin32HandleFromProtectedHandle ProtectedHandle   ; 戻り値は stat
; ProtectedHandle : HANDLE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "cldapi.dll"
#cfunc global CfGetWin32HandleFromProtectedHandle "CfGetWin32HandleFromProtectedHandle" sptr
; res = CfGetWin32HandleFromProtectedHandle(ProtectedHandle)
; ProtectedHandle : HANDLE -> "sptr"
; HANDLE CfGetWin32HandleFromProtectedHandle(HANDLE ProtectedHandle)
#uselib "cldapi.dll"
#cfunc global CfGetWin32HandleFromProtectedHandle "CfGetWin32HandleFromProtectedHandle" intptr
; res = CfGetWin32HandleFromProtectedHandle(ProtectedHandle)
; ProtectedHandle : HANDLE -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	cldapi = windows.NewLazySystemDLL("cldapi.dll")
	procCfGetWin32HandleFromProtectedHandle = cldapi.NewProc("CfGetWin32HandleFromProtectedHandle")
)

// ProtectedHandle (HANDLE)
r1, _, err := procCfGetWin32HandleFromProtectedHandle.Call(
	uintptr(ProtectedHandle),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function CfGetWin32HandleFromProtectedHandle(
  ProtectedHandle: THandle   // HANDLE
): THandle; stdcall;
  external 'cldapi.dll' name 'CfGetWin32HandleFromProtectedHandle';
result := DllCall("cldapi\CfGetWin32HandleFromProtectedHandle"
    , "Ptr", ProtectedHandle   ; HANDLE
    , "Ptr")   ; return: HANDLE
●CfGetWin32HandleFromProtectedHandle(ProtectedHandle) = DLL("cldapi.dll", "void* CfGetWin32HandleFromProtectedHandle(void*)")
# 呼び出し: CfGetWin32HandleFromProtectedHandle(ProtectedHandle)
# ProtectedHandle : HANDLE -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "cldapi" fn CfGetWin32HandleFromProtectedHandle(
    ProtectedHandle: ?*anyopaque // HANDLE
) callconv(std.os.windows.WINAPI) ?*anyopaque;
proc CfGetWin32HandleFromProtectedHandle(
    ProtectedHandle: pointer  # HANDLE
): pointer {.importc: "CfGetWin32HandleFromProtectedHandle", stdcall, dynlib: "cldapi.dll".}
pragma(lib, "cldapi");
extern(Windows)
void* CfGetWin32HandleFromProtectedHandle(
    void* ProtectedHandle   // HANDLE
);
ccall((:CfGetWin32HandleFromProtectedHandle, "cldapi.dll"), stdcall, Ptr{Cvoid},
      (Ptr{Cvoid},),
      ProtectedHandle)
# ProtectedHandle : HANDLE -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void* CfGetWin32HandleFromProtectedHandle(
    void* ProtectedHandle);
]]
local cldapi = ffi.load("cldapi")
-- cldapi.CfGetWin32HandleFromProtectedHandle(ProtectedHandle)
-- ProtectedHandle : HANDLE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('cldapi.dll');
const CfGetWin32HandleFromProtectedHandle = lib.func('__stdcall', 'CfGetWin32HandleFromProtectedHandle', 'void *', ['void *']);
// CfGetWin32HandleFromProtectedHandle(ProtectedHandle)
// ProtectedHandle : HANDLE -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("cldapi.dll", {
  CfGetWin32HandleFromProtectedHandle: { parameters: ["pointer"], result: "pointer" },
});
// lib.symbols.CfGetWin32HandleFromProtectedHandle(ProtectedHandle)
// ProtectedHandle : HANDLE -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* CfGetWin32HandleFromProtectedHandle(
    void* ProtectedHandle);
C, "cldapi.dll");
// $ffi->CfGetWin32HandleFromProtectedHandle(ProtectedHandle);
// ProtectedHandle : 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 Cldapi extends StdCallLibrary {
    Cldapi INSTANCE = Native.load("cldapi", Cldapi.class);
    Pointer CfGetWin32HandleFromProtectedHandle(
        Pointer ProtectedHandle   // HANDLE
    );
}
@[Link("cldapi")]
lib Libcldapi
  fun CfGetWin32HandleFromProtectedHandle = CfGetWin32HandleFromProtectedHandle(
    ProtectedHandle : Void*   # HANDLE
  ) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CfGetWin32HandleFromProtectedHandleNative = Pointer<Void> Function(Pointer<Void>);
typedef CfGetWin32HandleFromProtectedHandleDart = Pointer<Void> Function(Pointer<Void>);
final CfGetWin32HandleFromProtectedHandle = DynamicLibrary.open('cldapi.dll')
    .lookupFunction<CfGetWin32HandleFromProtectedHandleNative, CfGetWin32HandleFromProtectedHandleDart>('CfGetWin32HandleFromProtectedHandle');
// ProtectedHandle : HANDLE -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CfGetWin32HandleFromProtectedHandle(
  ProtectedHandle: THandle   // HANDLE
): THandle; stdcall;
  external 'cldapi.dll' name 'CfGetWin32HandleFromProtectedHandle';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CfGetWin32HandleFromProtectedHandle"
  c_CfGetWin32HandleFromProtectedHandle :: Ptr () -> IO (Ptr ())
-- ProtectedHandle : HANDLE -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let cfgetwin32handlefromprotectedhandle =
  foreign "CfGetWin32HandleFromProtectedHandle"
    ((ptr void) @-> returning (ptr void))
(* ProtectedHandle : HANDLE -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library cldapi (t "cldapi.dll"))
(cffi:use-foreign-library cldapi)

(cffi:defcfun ("CfGetWin32HandleFromProtectedHandle" cf-get-win32-handle-from-protected-handle :convention :stdcall) :pointer
  (protected-handle :pointer))   ; HANDLE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CfGetWin32HandleFromProtectedHandle = Win32::API::More->new('cldapi',
    'HANDLE CfGetWin32HandleFromProtectedHandle(HANDLE ProtectedHandle)');
# my $ret = $CfGetWin32HandleFromProtectedHandle->Call($ProtectedHandle);
# ProtectedHandle : HANDLE -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。