ホーム › Storage.InstallableFileSystems › FilterAttach
FilterAttach
関数指定ボリュームにミニフィルターインスタンスをアタッチする。
シグネチャ
// FLTLIB.dll
#include <windows.h>
HRESULT FilterAttach(
LPCWSTR lpFilterName,
LPCWSTR lpVolumeName,
LPCWSTR lpInstanceName, // optional
DWORD dwCreatedInstanceNameLength, // optional
LPWSTR lpCreatedInstanceName // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpFilterName | LPCWSTR | in | アタッチするミニフィルターのサービス名を指す。 |
| lpVolumeName | LPCWSTR | in | アタッチ先のボリューム名を指す。 |
| lpInstanceName | LPCWSTR | inoptional | 作成するインスタンスの名前を指す。NULL可。 |
| dwCreatedInstanceNameLength | DWORD | inoptional | lpCreatedInstanceNameバッファの長さを文字数で指定する。 |
| lpCreatedInstanceName | LPWSTR | outoptional | 生成されたインスタンス名を受け取るバッファを指す。NULL可。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// FLTLIB.dll
#include <windows.h>
HRESULT FilterAttach(
LPCWSTR lpFilterName,
LPCWSTR lpVolumeName,
LPCWSTR lpInstanceName, // optional
DWORD dwCreatedInstanceNameLength, // optional
LPWSTR lpCreatedInstanceName // optional
);[DllImport("FLTLIB.dll", ExactSpelling = true)]
static extern int FilterAttach(
[MarshalAs(UnmanagedType.LPWStr)] string lpFilterName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string lpVolumeName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string lpInstanceName, // LPCWSTR optional
uint dwCreatedInstanceNameLength, // DWORD optional
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpCreatedInstanceName // LPWSTR optional, out
);<DllImport("FLTLIB.dll", ExactSpelling:=True)>
Public Shared Function FilterAttach(
<MarshalAs(UnmanagedType.LPWStr)> lpFilterName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpVolumeName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpInstanceName As String, ' LPCWSTR optional
dwCreatedInstanceNameLength As UInteger, ' DWORD optional
<MarshalAs(UnmanagedType.LPWStr)> lpCreatedInstanceName As System.Text.StringBuilder ' LPWSTR optional, out
) As Integer
End Function' lpFilterName : LPCWSTR
' lpVolumeName : LPCWSTR
' lpInstanceName : LPCWSTR optional
' dwCreatedInstanceNameLength : DWORD optional
' lpCreatedInstanceName : LPWSTR optional, out
Declare PtrSafe Function FilterAttach Lib "fltlib" ( _
ByVal lpFilterName As LongPtr, _
ByVal lpVolumeName As LongPtr, _
ByVal lpInstanceName As LongPtr, _
ByVal dwCreatedInstanceNameLength As Long, _
ByVal lpCreatedInstanceName As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
FilterAttach = ctypes.windll.fltlib.FilterAttach
FilterAttach.restype = ctypes.c_int
FilterAttach.argtypes = [
wintypes.LPCWSTR, # lpFilterName : LPCWSTR
wintypes.LPCWSTR, # lpVolumeName : LPCWSTR
wintypes.LPCWSTR, # lpInstanceName : LPCWSTR optional
wintypes.DWORD, # dwCreatedInstanceNameLength : DWORD optional
wintypes.LPWSTR, # lpCreatedInstanceName : LPWSTR optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('FLTLIB.dll')
FilterAttach = Fiddle::Function.new(
lib['FilterAttach'],
[
Fiddle::TYPE_VOIDP, # lpFilterName : LPCWSTR
Fiddle::TYPE_VOIDP, # lpVolumeName : LPCWSTR
Fiddle::TYPE_VOIDP, # lpInstanceName : LPCWSTR optional
-Fiddle::TYPE_INT, # dwCreatedInstanceNameLength : DWORD optional
Fiddle::TYPE_VOIDP, # lpCreatedInstanceName : LPWSTR optional, out
],
Fiddle::TYPE_INT)#[link(name = "fltlib")]
extern "system" {
fn FilterAttach(
lpFilterName: *const u16, // LPCWSTR
lpVolumeName: *const u16, // LPCWSTR
lpInstanceName: *const u16, // LPCWSTR optional
dwCreatedInstanceNameLength: u32, // DWORD optional
lpCreatedInstanceName: *mut u16 // LPWSTR optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("FLTLIB.dll")]
public static extern int FilterAttach([MarshalAs(UnmanagedType.LPWStr)] string lpFilterName, [MarshalAs(UnmanagedType.LPWStr)] string lpVolumeName, [MarshalAs(UnmanagedType.LPWStr)] string lpInstanceName, uint dwCreatedInstanceNameLength, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpCreatedInstanceName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'FLTLIB_FilterAttach' -Namespace Win32 -PassThru
# $api::FilterAttach(lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, lpCreatedInstanceName)#uselib "FLTLIB.dll"
#func global FilterAttach "FilterAttach" sptr, sptr, sptr, sptr, sptr
; FilterAttach lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, varptr(lpCreatedInstanceName) ; 戻り値は stat
; lpFilterName : LPCWSTR -> "sptr"
; lpVolumeName : LPCWSTR -> "sptr"
; lpInstanceName : LPCWSTR optional -> "sptr"
; dwCreatedInstanceNameLength : DWORD optional -> "sptr"
; lpCreatedInstanceName : LPWSTR optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "FLTLIB.dll" #cfunc global FilterAttach "FilterAttach" wstr, wstr, wstr, int, var ; res = FilterAttach(lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, lpCreatedInstanceName) ; lpFilterName : LPCWSTR -> "wstr" ; lpVolumeName : LPCWSTR -> "wstr" ; lpInstanceName : LPCWSTR optional -> "wstr" ; dwCreatedInstanceNameLength : DWORD optional -> "int" ; lpCreatedInstanceName : LPWSTR optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "FLTLIB.dll" #cfunc global FilterAttach "FilterAttach" wstr, wstr, wstr, int, sptr ; res = FilterAttach(lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, varptr(lpCreatedInstanceName)) ; lpFilterName : LPCWSTR -> "wstr" ; lpVolumeName : LPCWSTR -> "wstr" ; lpInstanceName : LPCWSTR optional -> "wstr" ; dwCreatedInstanceNameLength : DWORD optional -> "int" ; lpCreatedInstanceName : LPWSTR optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT FilterAttach(LPCWSTR lpFilterName, LPCWSTR lpVolumeName, LPCWSTR lpInstanceName, DWORD dwCreatedInstanceNameLength, LPWSTR lpCreatedInstanceName) #uselib "FLTLIB.dll" #cfunc global FilterAttach "FilterAttach" wstr, wstr, wstr, int, var ; res = FilterAttach(lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, lpCreatedInstanceName) ; lpFilterName : LPCWSTR -> "wstr" ; lpVolumeName : LPCWSTR -> "wstr" ; lpInstanceName : LPCWSTR optional -> "wstr" ; dwCreatedInstanceNameLength : DWORD optional -> "int" ; lpCreatedInstanceName : LPWSTR optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT FilterAttach(LPCWSTR lpFilterName, LPCWSTR lpVolumeName, LPCWSTR lpInstanceName, DWORD dwCreatedInstanceNameLength, LPWSTR lpCreatedInstanceName) #uselib "FLTLIB.dll" #cfunc global FilterAttach "FilterAttach" wstr, wstr, wstr, int, intptr ; res = FilterAttach(lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, varptr(lpCreatedInstanceName)) ; lpFilterName : LPCWSTR -> "wstr" ; lpVolumeName : LPCWSTR -> "wstr" ; lpInstanceName : LPCWSTR optional -> "wstr" ; dwCreatedInstanceNameLength : DWORD optional -> "int" ; lpCreatedInstanceName : LPWSTR optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
fltlib = windows.NewLazySystemDLL("FLTLIB.dll")
procFilterAttach = fltlib.NewProc("FilterAttach")
)
// lpFilterName (LPCWSTR), lpVolumeName (LPCWSTR), lpInstanceName (LPCWSTR optional), dwCreatedInstanceNameLength (DWORD optional), lpCreatedInstanceName (LPWSTR optional, out)
r1, _, err := procFilterAttach.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFilterName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpVolumeName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpInstanceName))),
uintptr(dwCreatedInstanceNameLength),
uintptr(lpCreatedInstanceName),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction FilterAttach(
lpFilterName: PWideChar; // LPCWSTR
lpVolumeName: PWideChar; // LPCWSTR
lpInstanceName: PWideChar; // LPCWSTR optional
dwCreatedInstanceNameLength: DWORD; // DWORD optional
lpCreatedInstanceName: PWideChar // LPWSTR optional, out
): Integer; stdcall;
external 'FLTLIB.dll' name 'FilterAttach';result := DllCall("FLTLIB\FilterAttach"
, "WStr", lpFilterName ; LPCWSTR
, "WStr", lpVolumeName ; LPCWSTR
, "WStr", lpInstanceName ; LPCWSTR optional
, "UInt", dwCreatedInstanceNameLength ; DWORD optional
, "Ptr", lpCreatedInstanceName ; LPWSTR optional, out
, "Int") ; return: HRESULT●FilterAttach(lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, lpCreatedInstanceName) = DLL("FLTLIB.dll", "int FilterAttach(char*, char*, char*, dword, char*)")
# 呼び出し: FilterAttach(lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, lpCreatedInstanceName)
# lpFilterName : LPCWSTR -> "char*"
# lpVolumeName : LPCWSTR -> "char*"
# lpInstanceName : LPCWSTR optional -> "char*"
# dwCreatedInstanceNameLength : DWORD optional -> "dword"
# lpCreatedInstanceName : LPWSTR optional, out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "fltlib" fn FilterAttach(
lpFilterName: [*c]const u16, // LPCWSTR
lpVolumeName: [*c]const u16, // LPCWSTR
lpInstanceName: [*c]const u16, // LPCWSTR optional
dwCreatedInstanceNameLength: u32, // DWORD optional
lpCreatedInstanceName: [*c]u16 // LPWSTR optional, out
) callconv(std.os.windows.WINAPI) i32;proc FilterAttach(
lpFilterName: WideCString, # LPCWSTR
lpVolumeName: WideCString, # LPCWSTR
lpInstanceName: WideCString, # LPCWSTR optional
dwCreatedInstanceNameLength: uint32, # DWORD optional
lpCreatedInstanceName: ptr uint16 # LPWSTR optional, out
): int32 {.importc: "FilterAttach", stdcall, dynlib: "FLTLIB.dll".}pragma(lib, "fltlib");
extern(Windows)
int FilterAttach(
const(wchar)* lpFilterName, // LPCWSTR
const(wchar)* lpVolumeName, // LPCWSTR
const(wchar)* lpInstanceName, // LPCWSTR optional
uint dwCreatedInstanceNameLength, // DWORD optional
wchar* lpCreatedInstanceName // LPWSTR optional, out
);ccall((:FilterAttach, "FLTLIB.dll"), stdcall, Int32,
(Cwstring, Cwstring, Cwstring, UInt32, Ptr{UInt16}),
lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, lpCreatedInstanceName)
# lpFilterName : LPCWSTR -> Cwstring
# lpVolumeName : LPCWSTR -> Cwstring
# lpInstanceName : LPCWSTR optional -> Cwstring
# dwCreatedInstanceNameLength : DWORD optional -> UInt32
# lpCreatedInstanceName : LPWSTR optional, out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t FilterAttach(
const uint16_t* lpFilterName,
const uint16_t* lpVolumeName,
const uint16_t* lpInstanceName,
uint32_t dwCreatedInstanceNameLength,
uint16_t* lpCreatedInstanceName);
]]
local fltlib = ffi.load("fltlib")
-- fltlib.FilterAttach(lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, lpCreatedInstanceName)
-- lpFilterName : LPCWSTR
-- lpVolumeName : LPCWSTR
-- lpInstanceName : LPCWSTR optional
-- dwCreatedInstanceNameLength : DWORD optional
-- lpCreatedInstanceName : LPWSTR optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('FLTLIB.dll');
const FilterAttach = lib.func('__stdcall', 'FilterAttach', 'int32_t', ['str16', 'str16', 'str16', 'uint32_t', 'uint16_t *']);
// FilterAttach(lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, lpCreatedInstanceName)
// lpFilterName : LPCWSTR -> 'str16'
// lpVolumeName : LPCWSTR -> 'str16'
// lpInstanceName : LPCWSTR optional -> 'str16'
// dwCreatedInstanceNameLength : DWORD optional -> 'uint32_t'
// lpCreatedInstanceName : LPWSTR optional, out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("FLTLIB.dll", {
FilterAttach: { parameters: ["buffer", "buffer", "buffer", "u32", "buffer"], result: "i32" },
});
// lib.symbols.FilterAttach(lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, lpCreatedInstanceName)
// lpFilterName : LPCWSTR -> "buffer"
// lpVolumeName : LPCWSTR -> "buffer"
// lpInstanceName : LPCWSTR optional -> "buffer"
// dwCreatedInstanceNameLength : DWORD optional -> "u32"
// lpCreatedInstanceName : LPWSTR optional, out -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t FilterAttach(
const uint16_t* lpFilterName,
const uint16_t* lpVolumeName,
const uint16_t* lpInstanceName,
uint32_t dwCreatedInstanceNameLength,
uint16_t* lpCreatedInstanceName);
C, "FLTLIB.dll");
// $ffi->FilterAttach(lpFilterName, lpVolumeName, lpInstanceName, dwCreatedInstanceNameLength, lpCreatedInstanceName);
// lpFilterName : LPCWSTR
// lpVolumeName : LPCWSTR
// lpInstanceName : LPCWSTR optional
// dwCreatedInstanceNameLength : DWORD optional
// lpCreatedInstanceName : LPWSTR optional, out
// 構造体/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 Fltlib extends StdCallLibrary {
Fltlib INSTANCE = Native.load("fltlib", Fltlib.class);
int FilterAttach(
WString lpFilterName, // LPCWSTR
WString lpVolumeName, // LPCWSTR
WString lpInstanceName, // LPCWSTR optional
int dwCreatedInstanceNameLength, // DWORD optional
char[] lpCreatedInstanceName // LPWSTR optional, out
);
}@[Link("fltlib")]
lib LibFLTLIB
fun FilterAttach = FilterAttach(
lpFilterName : UInt16*, # LPCWSTR
lpVolumeName : UInt16*, # LPCWSTR
lpInstanceName : UInt16*, # LPCWSTR optional
dwCreatedInstanceNameLength : UInt32, # DWORD optional
lpCreatedInstanceName : UInt16* # LPWSTR optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef FilterAttachNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Utf16>);
typedef FilterAttachDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Utf16>);
final FilterAttach = DynamicLibrary.open('FLTLIB.dll')
.lookupFunction<FilterAttachNative, FilterAttachDart>('FilterAttach');
// lpFilterName : LPCWSTR -> Pointer<Utf16>
// lpVolumeName : LPCWSTR -> Pointer<Utf16>
// lpInstanceName : LPCWSTR optional -> Pointer<Utf16>
// dwCreatedInstanceNameLength : DWORD optional -> Uint32
// lpCreatedInstanceName : LPWSTR optional, out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function FilterAttach(
lpFilterName: PWideChar; // LPCWSTR
lpVolumeName: PWideChar; // LPCWSTR
lpInstanceName: PWideChar; // LPCWSTR optional
dwCreatedInstanceNameLength: DWORD; // DWORD optional
lpCreatedInstanceName: PWideChar // LPWSTR optional, out
): Integer; stdcall;
external 'FLTLIB.dll' name 'FilterAttach';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "FilterAttach"
c_FilterAttach :: CWString -> CWString -> CWString -> Word32 -> CWString -> IO Int32
-- lpFilterName : LPCWSTR -> CWString
-- lpVolumeName : LPCWSTR -> CWString
-- lpInstanceName : LPCWSTR optional -> CWString
-- dwCreatedInstanceNameLength : DWORD optional -> Word32
-- lpCreatedInstanceName : LPWSTR optional, out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let filterattach =
foreign "FilterAttach"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> returning int32_t)
(* lpFilterName : LPCWSTR -> (ptr uint16_t) *)
(* lpVolumeName : LPCWSTR -> (ptr uint16_t) *)
(* lpInstanceName : LPCWSTR optional -> (ptr uint16_t) *)
(* dwCreatedInstanceNameLength : DWORD optional -> uint32_t *)
(* lpCreatedInstanceName : LPWSTR optional, out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library fltlib (t "FLTLIB.dll"))
(cffi:use-foreign-library fltlib)
(cffi:defcfun ("FilterAttach" filter-attach :convention :stdcall) :int32
(lp-filter-name (:string :encoding :utf-16le)) ; LPCWSTR
(lp-volume-name (:string :encoding :utf-16le)) ; LPCWSTR
(lp-instance-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-created-instance-name-length :uint32) ; DWORD optional
(lp-created-instance-name :pointer)) ; LPWSTR optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $FilterAttach = Win32::API::More->new('FLTLIB',
'int FilterAttach(LPCWSTR lpFilterName, LPCWSTR lpVolumeName, LPCWSTR lpInstanceName, DWORD dwCreatedInstanceNameLength, LPWSTR lpCreatedInstanceName)');
# my $ret = $FilterAttach->Call($lpFilterName, $lpVolumeName, $lpInstanceName, $dwCreatedInstanceNameLength, $lpCreatedInstanceName);
# lpFilterName : LPCWSTR -> LPCWSTR
# lpVolumeName : LPCWSTR -> LPCWSTR
# lpInstanceName : LPCWSTR optional -> LPCWSTR
# dwCreatedInstanceNameLength : DWORD optional -> DWORD
# lpCreatedInstanceName : LPWSTR optional, out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。