ホーム › Storage.FileSystem › WofSetFileDataLocation
WofSetFileDataLocation
関数WOFプロバイダーでファイルデータの格納先を設定する。
シグネチャ
// WOFUTIL.dll
#include <windows.h>
HRESULT WofSetFileDataLocation(
HANDLE FileHandle,
DWORD Provider,
void* ExternalFileInfo,
DWORD Length
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||
|---|---|---|---|---|---|---|---|
| FileHandle | HANDLE | in | CreateFile または同様の API で開いたファイルへのハンドルです。 | ||||
| Provider | DWORD | in | このファイルをバッキングするプロバイダーを示します。現在定義されているプロバイダーは次のとおりです。
| ||||
| ExternalFileInfo | void* | in | 指定されたプロバイダーに固有のデータを提供します。定義されている各プロバイダーのデータ構造体は次のとおりです。
| ||||
| Length | DWORD | in | プロバイダー固有のデータの長さをバイト単位で指定します。これは上記で定義された構造体に対応している必要があります。
|
戻り値の型: HRESULT
公式ドキュメント
物理ファイルによってバッキングされているファイルを、システムデータプロバイダーによってバッキングされる形式に変更するために使用します。
戻り値
この関数は、成功または失敗の理由を示す HRESULT を返します。
解説(Remarks)
WOF_PROVIDER_FILE を使用する場合、操作が ERROR_COMPRESSION_NOT_BENEFICIAL で失敗することがあります。これは、データの圧縮が試みられたものの、ディスク領域が節約されなかったためにファイルが圧縮されなかったことを示します。ほとんどのアプリケーションでは、これは成功条件として扱うことができます。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WOFUTIL.dll
#include <windows.h>
HRESULT WofSetFileDataLocation(
HANDLE FileHandle,
DWORD Provider,
void* ExternalFileInfo,
DWORD Length
);[DllImport("WOFUTIL.dll", ExactSpelling = true)]
static extern int WofSetFileDataLocation(
IntPtr FileHandle, // HANDLE
uint Provider, // DWORD
IntPtr ExternalFileInfo, // void*
uint Length // DWORD
);<DllImport("WOFUTIL.dll", ExactSpelling:=True)>
Public Shared Function WofSetFileDataLocation(
FileHandle As IntPtr, ' HANDLE
Provider As UInteger, ' DWORD
ExternalFileInfo As IntPtr, ' void*
Length As UInteger ' DWORD
) As Integer
End Function' FileHandle : HANDLE
' Provider : DWORD
' ExternalFileInfo : void*
' Length : DWORD
Declare PtrSafe Function WofSetFileDataLocation Lib "wofutil" ( _
ByVal FileHandle As LongPtr, _
ByVal Provider As Long, _
ByVal ExternalFileInfo As LongPtr, _
ByVal Length As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WofSetFileDataLocation = ctypes.windll.wofutil.WofSetFileDataLocation
WofSetFileDataLocation.restype = ctypes.c_int
WofSetFileDataLocation.argtypes = [
wintypes.HANDLE, # FileHandle : HANDLE
wintypes.DWORD, # Provider : DWORD
ctypes.POINTER(None), # ExternalFileInfo : void*
wintypes.DWORD, # Length : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WOFUTIL.dll')
WofSetFileDataLocation = Fiddle::Function.new(
lib['WofSetFileDataLocation'],
[
Fiddle::TYPE_VOIDP, # FileHandle : HANDLE
-Fiddle::TYPE_INT, # Provider : DWORD
Fiddle::TYPE_VOIDP, # ExternalFileInfo : void*
-Fiddle::TYPE_INT, # Length : DWORD
],
Fiddle::TYPE_INT)#[link(name = "wofutil")]
extern "system" {
fn WofSetFileDataLocation(
FileHandle: *mut core::ffi::c_void, // HANDLE
Provider: u32, // DWORD
ExternalFileInfo: *mut (), // void*
Length: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WOFUTIL.dll")]
public static extern int WofSetFileDataLocation(IntPtr FileHandle, uint Provider, IntPtr ExternalFileInfo, uint Length);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WOFUTIL_WofSetFileDataLocation' -Namespace Win32 -PassThru
# $api::WofSetFileDataLocation(FileHandle, Provider, ExternalFileInfo, Length)#uselib "WOFUTIL.dll"
#func global WofSetFileDataLocation "WofSetFileDataLocation" sptr, sptr, sptr, sptr
; WofSetFileDataLocation FileHandle, Provider, ExternalFileInfo, Length ; 戻り値は stat
; FileHandle : HANDLE -> "sptr"
; Provider : DWORD -> "sptr"
; ExternalFileInfo : void* -> "sptr"
; Length : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WOFUTIL.dll"
#cfunc global WofSetFileDataLocation "WofSetFileDataLocation" sptr, int, sptr, int
; res = WofSetFileDataLocation(FileHandle, Provider, ExternalFileInfo, Length)
; FileHandle : HANDLE -> "sptr"
; Provider : DWORD -> "int"
; ExternalFileInfo : void* -> "sptr"
; Length : DWORD -> "int"; HRESULT WofSetFileDataLocation(HANDLE FileHandle, DWORD Provider, void* ExternalFileInfo, DWORD Length)
#uselib "WOFUTIL.dll"
#cfunc global WofSetFileDataLocation "WofSetFileDataLocation" intptr, int, intptr, int
; res = WofSetFileDataLocation(FileHandle, Provider, ExternalFileInfo, Length)
; FileHandle : HANDLE -> "intptr"
; Provider : DWORD -> "int"
; ExternalFileInfo : void* -> "intptr"
; Length : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wofutil = windows.NewLazySystemDLL("WOFUTIL.dll")
procWofSetFileDataLocation = wofutil.NewProc("WofSetFileDataLocation")
)
// FileHandle (HANDLE), Provider (DWORD), ExternalFileInfo (void*), Length (DWORD)
r1, _, err := procWofSetFileDataLocation.Call(
uintptr(FileHandle),
uintptr(Provider),
uintptr(ExternalFileInfo),
uintptr(Length),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction WofSetFileDataLocation(
FileHandle: THandle; // HANDLE
Provider: DWORD; // DWORD
ExternalFileInfo: Pointer; // void*
Length: DWORD // DWORD
): Integer; stdcall;
external 'WOFUTIL.dll' name 'WofSetFileDataLocation';result := DllCall("WOFUTIL\WofSetFileDataLocation"
, "Ptr", FileHandle ; HANDLE
, "UInt", Provider ; DWORD
, "Ptr", ExternalFileInfo ; void*
, "UInt", Length ; DWORD
, "Int") ; return: HRESULT●WofSetFileDataLocation(FileHandle, Provider, ExternalFileInfo, Length) = DLL("WOFUTIL.dll", "int WofSetFileDataLocation(void*, dword, void*, dword)")
# 呼び出し: WofSetFileDataLocation(FileHandle, Provider, ExternalFileInfo, Length)
# FileHandle : HANDLE -> "void*"
# Provider : DWORD -> "dword"
# ExternalFileInfo : void* -> "void*"
# Length : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wofutil" fn WofSetFileDataLocation(
FileHandle: ?*anyopaque, // HANDLE
Provider: u32, // DWORD
ExternalFileInfo: ?*anyopaque, // void*
Length: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc WofSetFileDataLocation(
FileHandle: pointer, # HANDLE
Provider: uint32, # DWORD
ExternalFileInfo: pointer, # void*
Length: uint32 # DWORD
): int32 {.importc: "WofSetFileDataLocation", stdcall, dynlib: "WOFUTIL.dll".}pragma(lib, "wofutil");
extern(Windows)
int WofSetFileDataLocation(
void* FileHandle, // HANDLE
uint Provider, // DWORD
void* ExternalFileInfo, // void*
uint Length // DWORD
);ccall((:WofSetFileDataLocation, "WOFUTIL.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, Ptr{Cvoid}, UInt32),
FileHandle, Provider, ExternalFileInfo, Length)
# FileHandle : HANDLE -> Ptr{Cvoid}
# Provider : DWORD -> UInt32
# ExternalFileInfo : void* -> Ptr{Cvoid}
# Length : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t WofSetFileDataLocation(
void* FileHandle,
uint32_t Provider,
void* ExternalFileInfo,
uint32_t Length);
]]
local wofutil = ffi.load("wofutil")
-- wofutil.WofSetFileDataLocation(FileHandle, Provider, ExternalFileInfo, Length)
-- FileHandle : HANDLE
-- Provider : DWORD
-- ExternalFileInfo : void*
-- Length : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WOFUTIL.dll');
const WofSetFileDataLocation = lib.func('__stdcall', 'WofSetFileDataLocation', 'int32_t', ['void *', 'uint32_t', 'void *', 'uint32_t']);
// WofSetFileDataLocation(FileHandle, Provider, ExternalFileInfo, Length)
// FileHandle : HANDLE -> 'void *'
// Provider : DWORD -> 'uint32_t'
// ExternalFileInfo : void* -> 'void *'
// Length : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WOFUTIL.dll", {
WofSetFileDataLocation: { parameters: ["pointer", "u32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.WofSetFileDataLocation(FileHandle, Provider, ExternalFileInfo, Length)
// FileHandle : HANDLE -> "pointer"
// Provider : DWORD -> "u32"
// ExternalFileInfo : void* -> "pointer"
// Length : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WofSetFileDataLocation(
void* FileHandle,
uint32_t Provider,
void* ExternalFileInfo,
uint32_t Length);
C, "WOFUTIL.dll");
// $ffi->WofSetFileDataLocation(FileHandle, Provider, ExternalFileInfo, Length);
// FileHandle : HANDLE
// Provider : DWORD
// ExternalFileInfo : void*
// Length : DWORD
// 構造体/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 Wofutil extends StdCallLibrary {
Wofutil INSTANCE = Native.load("wofutil", Wofutil.class);
int WofSetFileDataLocation(
Pointer FileHandle, // HANDLE
int Provider, // DWORD
Pointer ExternalFileInfo, // void*
int Length // DWORD
);
}@[Link("wofutil")]
lib LibWOFUTIL
fun WofSetFileDataLocation = WofSetFileDataLocation(
FileHandle : Void*, # HANDLE
Provider : UInt32, # DWORD
ExternalFileInfo : Void*, # void*
Length : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WofSetFileDataLocationNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Uint32);
typedef WofSetFileDataLocationDart = int Function(Pointer<Void>, int, Pointer<Void>, int);
final WofSetFileDataLocation = DynamicLibrary.open('WOFUTIL.dll')
.lookupFunction<WofSetFileDataLocationNative, WofSetFileDataLocationDart>('WofSetFileDataLocation');
// FileHandle : HANDLE -> Pointer<Void>
// Provider : DWORD -> Uint32
// ExternalFileInfo : void* -> Pointer<Void>
// Length : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WofSetFileDataLocation(
FileHandle: THandle; // HANDLE
Provider: DWORD; // DWORD
ExternalFileInfo: Pointer; // void*
Length: DWORD // DWORD
): Integer; stdcall;
external 'WOFUTIL.dll' name 'WofSetFileDataLocation';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WofSetFileDataLocation"
c_WofSetFileDataLocation :: Ptr () -> Word32 -> Ptr () -> Word32 -> IO Int32
-- FileHandle : HANDLE -> Ptr ()
-- Provider : DWORD -> Word32
-- ExternalFileInfo : void* -> Ptr ()
-- Length : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wofsetfiledatalocation =
foreign "WofSetFileDataLocation"
((ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* FileHandle : HANDLE -> (ptr void) *)
(* Provider : DWORD -> uint32_t *)
(* ExternalFileInfo : void* -> (ptr void) *)
(* Length : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wofutil (t "WOFUTIL.dll"))
(cffi:use-foreign-library wofutil)
(cffi:defcfun ("WofSetFileDataLocation" wof-set-file-data-location :convention :stdcall) :int32
(file-handle :pointer) ; HANDLE
(provider :uint32) ; DWORD
(external-file-info :pointer) ; void*
(length :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WofSetFileDataLocation = Win32::API::More->new('WOFUTIL',
'int WofSetFileDataLocation(HANDLE FileHandle, DWORD Provider, LPVOID ExternalFileInfo, DWORD Length)');
# my $ret = $WofSetFileDataLocation->Call($FileHandle, $Provider, $ExternalFileInfo, $Length);
# FileHandle : HANDLE -> HANDLE
# Provider : DWORD -> DWORD
# ExternalFileInfo : void* -> LPVOID
# Length : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。