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

CreateBindLink

関数
仮想パスを実体パスへ結び付けるバインドリンクを作成する。
DLLBINDFLTAPI.dll呼出規約winapi

シグネチャ

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

HRESULT CreateBindLink(
    LPCWSTR virtualPath,
    LPCWSTR backingPath,
    CREATE_BIND_LINK_FLAGS createBindLinkFlags,
    DWORD exceptionCount,
    LPCWSTR* exceptionPaths   // optional
);

パラメーター

名前方向説明
virtualPathLPCWSTRin仮想的に見せるパス(バインドリンクのマッピング元)を指す文字列。
backingPathLPCWSTRinvirtualPathの実体となる背後のパスを指す文字列。
createBindLinkFlagsCREATE_BIND_LINK_FLAGSinバインドリンク作成時の動作を制御するフラグ(CREATE_BIND_LINK_FLAGS)。読み取り専用やマージなどを指定する。
exceptionCountDWORDinexceptionPaths配列に含まれる除外パスの数。
exceptionPathsLPCWSTR*inoptionalマッピングから除外するパスの配列へのポインタ。除外がなければNULL可。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT CreateBindLink(
    LPCWSTR virtualPath,
    LPCWSTR backingPath,
    CREATE_BIND_LINK_FLAGS createBindLinkFlags,
    DWORD exceptionCount,
    LPCWSTR* exceptionPaths   // optional
);
[DllImport("BINDFLTAPI.dll", ExactSpelling = true)]
static extern int CreateBindLink(
    [MarshalAs(UnmanagedType.LPWStr)] string virtualPath,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string backingPath,   // LPCWSTR
    int createBindLinkFlags,   // CREATE_BIND_LINK_FLAGS
    uint exceptionCount,   // DWORD
    IntPtr exceptionPaths   // LPCWSTR* optional
);
<DllImport("BINDFLTAPI.dll", ExactSpelling:=True)>
Public Shared Function CreateBindLink(
    <MarshalAs(UnmanagedType.LPWStr)> virtualPath As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> backingPath As String,   ' LPCWSTR
    createBindLinkFlags As Integer,   ' CREATE_BIND_LINK_FLAGS
    exceptionCount As UInteger,   ' DWORD
    exceptionPaths As IntPtr   ' LPCWSTR* optional
) As Integer
End Function
' virtualPath : LPCWSTR
' backingPath : LPCWSTR
' createBindLinkFlags : CREATE_BIND_LINK_FLAGS
' exceptionCount : DWORD
' exceptionPaths : LPCWSTR* optional
Declare PtrSafe Function CreateBindLink Lib "bindfltapi" ( _
    ByVal virtualPath As LongPtr, _
    ByVal backingPath As LongPtr, _
    ByVal createBindLinkFlags As Long, _
    ByVal exceptionCount As Long, _
    ByVal exceptionPaths As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateBindLink = ctypes.windll.bindfltapi.CreateBindLink
CreateBindLink.restype = ctypes.c_int
CreateBindLink.argtypes = [
    wintypes.LPCWSTR,  # virtualPath : LPCWSTR
    wintypes.LPCWSTR,  # backingPath : LPCWSTR
    ctypes.c_int,  # createBindLinkFlags : CREATE_BIND_LINK_FLAGS
    wintypes.DWORD,  # exceptionCount : DWORD
    ctypes.c_void_p,  # exceptionPaths : LPCWSTR* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('BINDFLTAPI.dll')
CreateBindLink = Fiddle::Function.new(
  lib['CreateBindLink'],
  [
    Fiddle::TYPE_VOIDP,  # virtualPath : LPCWSTR
    Fiddle::TYPE_VOIDP,  # backingPath : LPCWSTR
    Fiddle::TYPE_INT,  # createBindLinkFlags : CREATE_BIND_LINK_FLAGS
    -Fiddle::TYPE_INT,  # exceptionCount : DWORD
    Fiddle::TYPE_VOIDP,  # exceptionPaths : LPCWSTR* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "bindfltapi")]
extern "system" {
    fn CreateBindLink(
        virtualPath: *const u16,  // LPCWSTR
        backingPath: *const u16,  // LPCWSTR
        createBindLinkFlags: i32,  // CREATE_BIND_LINK_FLAGS
        exceptionCount: u32,  // DWORD
        exceptionPaths: *const *const u16  // LPCWSTR* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("BINDFLTAPI.dll")]
public static extern int CreateBindLink([MarshalAs(UnmanagedType.LPWStr)] string virtualPath, [MarshalAs(UnmanagedType.LPWStr)] string backingPath, int createBindLinkFlags, uint exceptionCount, IntPtr exceptionPaths);
"@
$api = Add-Type -MemberDefinition $sig -Name 'BINDFLTAPI_CreateBindLink' -Namespace Win32 -PassThru
# $api::CreateBindLink(virtualPath, backingPath, createBindLinkFlags, exceptionCount, exceptionPaths)
#uselib "BINDFLTAPI.dll"
#func global CreateBindLink "CreateBindLink" sptr, sptr, sptr, sptr, sptr
; CreateBindLink virtualPath, backingPath, createBindLinkFlags, exceptionCount, varptr(exceptionPaths)   ; 戻り値は stat
; virtualPath : LPCWSTR -> "sptr"
; backingPath : LPCWSTR -> "sptr"
; createBindLinkFlags : CREATE_BIND_LINK_FLAGS -> "sptr"
; exceptionCount : DWORD -> "sptr"
; exceptionPaths : LPCWSTR* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "BINDFLTAPI.dll"
#cfunc global CreateBindLink "CreateBindLink" wstr, wstr, int, int, var
; res = CreateBindLink(virtualPath, backingPath, createBindLinkFlags, exceptionCount, exceptionPaths)
; virtualPath : LPCWSTR -> "wstr"
; backingPath : LPCWSTR -> "wstr"
; createBindLinkFlags : CREATE_BIND_LINK_FLAGS -> "int"
; exceptionCount : DWORD -> "int"
; exceptionPaths : LPCWSTR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT CreateBindLink(LPCWSTR virtualPath, LPCWSTR backingPath, CREATE_BIND_LINK_FLAGS createBindLinkFlags, DWORD exceptionCount, LPCWSTR* exceptionPaths)
#uselib "BINDFLTAPI.dll"
#cfunc global CreateBindLink "CreateBindLink" wstr, wstr, int, int, var
; res = CreateBindLink(virtualPath, backingPath, createBindLinkFlags, exceptionCount, exceptionPaths)
; virtualPath : LPCWSTR -> "wstr"
; backingPath : LPCWSTR -> "wstr"
; createBindLinkFlags : CREATE_BIND_LINK_FLAGS -> "int"
; exceptionCount : DWORD -> "int"
; exceptionPaths : LPCWSTR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	bindfltapi = windows.NewLazySystemDLL("BINDFLTAPI.dll")
	procCreateBindLink = bindfltapi.NewProc("CreateBindLink")
)

// virtualPath (LPCWSTR), backingPath (LPCWSTR), createBindLinkFlags (CREATE_BIND_LINK_FLAGS), exceptionCount (DWORD), exceptionPaths (LPCWSTR* optional)
r1, _, err := procCreateBindLink.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(virtualPath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(backingPath))),
	uintptr(createBindLinkFlags),
	uintptr(exceptionCount),
	uintptr(exceptionPaths),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function CreateBindLink(
  virtualPath: PWideChar;   // LPCWSTR
  backingPath: PWideChar;   // LPCWSTR
  createBindLinkFlags: Integer;   // CREATE_BIND_LINK_FLAGS
  exceptionCount: DWORD;   // DWORD
  exceptionPaths: PPWideChar   // LPCWSTR* optional
): Integer; stdcall;
  external 'BINDFLTAPI.dll' name 'CreateBindLink';
result := DllCall("BINDFLTAPI\CreateBindLink"
    , "WStr", virtualPath   ; LPCWSTR
    , "WStr", backingPath   ; LPCWSTR
    , "Int", createBindLinkFlags   ; CREATE_BIND_LINK_FLAGS
    , "UInt", exceptionCount   ; DWORD
    , "Ptr", exceptionPaths   ; LPCWSTR* optional
    , "Int")   ; return: HRESULT
●CreateBindLink(virtualPath, backingPath, createBindLinkFlags, exceptionCount, exceptionPaths) = DLL("BINDFLTAPI.dll", "int CreateBindLink(char*, char*, int, dword, void*)")
# 呼び出し: CreateBindLink(virtualPath, backingPath, createBindLinkFlags, exceptionCount, exceptionPaths)
# virtualPath : LPCWSTR -> "char*"
# backingPath : LPCWSTR -> "char*"
# createBindLinkFlags : CREATE_BIND_LINK_FLAGS -> "int"
# exceptionCount : DWORD -> "dword"
# exceptionPaths : LPCWSTR* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "bindfltapi" fn CreateBindLink(
    virtualPath: [*c]const u16, // LPCWSTR
    backingPath: [*c]const u16, // LPCWSTR
    createBindLinkFlags: i32, // CREATE_BIND_LINK_FLAGS
    exceptionCount: u32, // DWORD
    exceptionPaths: [*c][*c]u16 // LPCWSTR* optional
) callconv(std.os.windows.WINAPI) i32;
proc CreateBindLink(
    virtualPath: WideCString,  # LPCWSTR
    backingPath: WideCString,  # LPCWSTR
    createBindLinkFlags: int32,  # CREATE_BIND_LINK_FLAGS
    exceptionCount: uint32,  # DWORD
    exceptionPaths: ptr WideCString  # LPCWSTR* optional
): int32 {.importc: "CreateBindLink", stdcall, dynlib: "BINDFLTAPI.dll".}
pragma(lib, "bindfltapi");
extern(Windows)
int CreateBindLink(
    const(wchar)* virtualPath,   // LPCWSTR
    const(wchar)* backingPath,   // LPCWSTR
    int createBindLinkFlags,   // CREATE_BIND_LINK_FLAGS
    uint exceptionCount,   // DWORD
    wchar** exceptionPaths   // LPCWSTR* optional
);
ccall((:CreateBindLink, "BINDFLTAPI.dll"), stdcall, Int32,
      (Cwstring, Cwstring, Int32, UInt32, Ptr{Ptr{UInt16}}),
      virtualPath, backingPath, createBindLinkFlags, exceptionCount, exceptionPaths)
# virtualPath : LPCWSTR -> Cwstring
# backingPath : LPCWSTR -> Cwstring
# createBindLinkFlags : CREATE_BIND_LINK_FLAGS -> Int32
# exceptionCount : DWORD -> UInt32
# exceptionPaths : LPCWSTR* optional -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CreateBindLink(
    const uint16_t* virtualPath,
    const uint16_t* backingPath,
    int32_t createBindLinkFlags,
    uint32_t exceptionCount,
    uint16_t** exceptionPaths);
]]
local bindfltapi = ffi.load("bindfltapi")
-- bindfltapi.CreateBindLink(virtualPath, backingPath, createBindLinkFlags, exceptionCount, exceptionPaths)
-- virtualPath : LPCWSTR
-- backingPath : LPCWSTR
-- createBindLinkFlags : CREATE_BIND_LINK_FLAGS
-- exceptionCount : DWORD
-- exceptionPaths : LPCWSTR* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('BINDFLTAPI.dll');
const CreateBindLink = lib.func('__stdcall', 'CreateBindLink', 'int32_t', ['str16', 'str16', 'int32_t', 'uint32_t', 'void *']);
// CreateBindLink(virtualPath, backingPath, createBindLinkFlags, exceptionCount, exceptionPaths)
// virtualPath : LPCWSTR -> 'str16'
// backingPath : LPCWSTR -> 'str16'
// createBindLinkFlags : CREATE_BIND_LINK_FLAGS -> 'int32_t'
// exceptionCount : DWORD -> 'uint32_t'
// exceptionPaths : LPCWSTR* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("BINDFLTAPI.dll", {
  CreateBindLink: { parameters: ["buffer", "buffer", "i32", "u32", "pointer"], result: "i32" },
});
// lib.symbols.CreateBindLink(virtualPath, backingPath, createBindLinkFlags, exceptionCount, exceptionPaths)
// virtualPath : LPCWSTR -> "buffer"
// backingPath : LPCWSTR -> "buffer"
// createBindLinkFlags : CREATE_BIND_LINK_FLAGS -> "i32"
// exceptionCount : DWORD -> "u32"
// exceptionPaths : LPCWSTR* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CreateBindLink(
    const uint16_t* virtualPath,
    const uint16_t* backingPath,
    int32_t createBindLinkFlags,
    uint32_t exceptionCount,
    uint16_t** exceptionPaths);
C, "BINDFLTAPI.dll");
// $ffi->CreateBindLink(virtualPath, backingPath, createBindLinkFlags, exceptionCount, exceptionPaths);
// virtualPath : LPCWSTR
// backingPath : LPCWSTR
// createBindLinkFlags : CREATE_BIND_LINK_FLAGS
// exceptionCount : DWORD
// exceptionPaths : LPCWSTR* optional
// 構造体/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 Bindfltapi extends StdCallLibrary {
    Bindfltapi INSTANCE = Native.load("bindfltapi", Bindfltapi.class);
    int CreateBindLink(
        WString virtualPath,   // LPCWSTR
        WString backingPath,   // LPCWSTR
        int createBindLinkFlags,   // CREATE_BIND_LINK_FLAGS
        int exceptionCount,   // DWORD
        PointerByReference exceptionPaths   // LPCWSTR* optional
    );
}
@[Link("bindfltapi")]
lib LibBINDFLTAPI
  fun CreateBindLink = CreateBindLink(
    virtualPath : UInt16*,   # LPCWSTR
    backingPath : UInt16*,   # LPCWSTR
    createBindLinkFlags : Int32,   # CREATE_BIND_LINK_FLAGS
    exceptionCount : UInt32,   # DWORD
    exceptionPaths : UInt16**   # LPCWSTR* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CreateBindLinkNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Int32, Uint32, Pointer<Pointer<Utf16>>);
typedef CreateBindLinkDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, int, Pointer<Pointer<Utf16>>);
final CreateBindLink = DynamicLibrary.open('BINDFLTAPI.dll')
    .lookupFunction<CreateBindLinkNative, CreateBindLinkDart>('CreateBindLink');
// virtualPath : LPCWSTR -> Pointer<Utf16>
// backingPath : LPCWSTR -> Pointer<Utf16>
// createBindLinkFlags : CREATE_BIND_LINK_FLAGS -> Int32
// exceptionCount : DWORD -> Uint32
// exceptionPaths : LPCWSTR* optional -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateBindLink(
  virtualPath: PWideChar;   // LPCWSTR
  backingPath: PWideChar;   // LPCWSTR
  createBindLinkFlags: Integer;   // CREATE_BIND_LINK_FLAGS
  exceptionCount: DWORD;   // DWORD
  exceptionPaths: PPWideChar   // LPCWSTR* optional
): Integer; stdcall;
  external 'BINDFLTAPI.dll' name 'CreateBindLink';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateBindLink"
  c_CreateBindLink :: CWString -> CWString -> Int32 -> Word32 -> Ptr CWString -> IO Int32
-- virtualPath : LPCWSTR -> CWString
-- backingPath : LPCWSTR -> CWString
-- createBindLinkFlags : CREATE_BIND_LINK_FLAGS -> Int32
-- exceptionCount : DWORD -> Word32
-- exceptionPaths : LPCWSTR* optional -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createbindlink =
  foreign "CreateBindLink"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> uint32_t @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* virtualPath : LPCWSTR -> (ptr uint16_t) *)
(* backingPath : LPCWSTR -> (ptr uint16_t) *)
(* createBindLinkFlags : CREATE_BIND_LINK_FLAGS -> int32_t *)
(* exceptionCount : DWORD -> uint32_t *)
(* exceptionPaths : LPCWSTR* optional -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library bindfltapi (t "BINDFLTAPI.dll"))
(cffi:use-foreign-library bindfltapi)

(cffi:defcfun ("CreateBindLink" create-bind-link :convention :stdcall) :int32
  (virtual-path (:string :encoding :utf-16le))   ; LPCWSTR
  (backing-path (:string :encoding :utf-16le))   ; LPCWSTR
  (create-bind-link-flags :int32)   ; CREATE_BIND_LINK_FLAGS
  (exception-count :uint32)   ; DWORD
  (exception-paths :pointer))   ; LPCWSTR* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateBindLink = Win32::API::More->new('BINDFLTAPI',
    'int CreateBindLink(LPCWSTR virtualPath, LPCWSTR backingPath, int createBindLinkFlags, DWORD exceptionCount, LPVOID exceptionPaths)');
# my $ret = $CreateBindLink->Call($virtualPath, $backingPath, $createBindLinkFlags, $exceptionCount, $exceptionPaths);
# virtualPath : LPCWSTR -> LPCWSTR
# backingPath : LPCWSTR -> LPCWSTR
# createBindLinkFlags : CREATE_BIND_LINK_FLAGS -> int
# exceptionCount : DWORD -> DWORD
# exceptionPaths : LPCWSTR* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型