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