ホーム › Storage.FileSystem › Wow64EnableWow64FsRedirection
Wow64EnableWow64FsRedirection
関数WOW64のファイルシステムリダイレクトを有効または無効に切り替える。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOLEAN Wow64EnableWow64FsRedirection(
BOOLEAN Wow64FsEnableRedirection
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Wow64FsEnableRedirection | BOOLEAN | in | WOW64 システムフォルダーリダイレクトに対する要求の種類を示します。 TRUE の場合はリダイレクトの有効化を要求し、FALSE の場合はリダイレクトの無効化を要求します。 |
戻り値の型: BOOLEAN
公式ドキュメント
呼び出し元スレッドのファイルシステムリダイレクトを有効または無効にします。
戻り値
関数が成功したかどうかを示すブール値です。TRUE の場合は関数が成功したことを示し、FALSE の場合は関数が失敗したことを示します。
解説(Remarks)
この関数は、ネイティブの system32 ディレクトリにアクセスしたい 32 ビットアプリケーションにとって有用です。既定では、WOW64 ファイルシステムリダイレクトは有効になっています。
注意 Wow64EnableWow64FsRedirection 関数は、現在のスレッドが実行するすべてのファイル操作に影響します。そのため、ファイルシステムリダイレクトを長時間無効にすると、意図しない結果を招くことがあります。たとえば、DLL の読み込みはファイルシステムリダイレクトに依存しているため、ファイルシステムリダイレクトを無効にすると DLL の読み込みが失敗します。また、多くの機能の実装は遅延読み込みを使用しており、リダイレクトが無効な間は失敗します。最初の遅延読み込み操作の失敗状態は保持されるため、ファイルシステムリダイレクトを再度有効にした後でも、その遅延読み込み関数を以降使用すると失敗します。これらの問題を回避するには、リダイレクトされてはならない特定のファイル I/O 関数(CreateFile など)の呼び出しの直前にファイルシステムリダイレクトを無効にし、その直後に
Wow64EnableWow64FsRedirection(TRUE) を使用してファイルシステムリダイレクトを再度有効にしてください。Windows 8 および Windows Server 2012 では、この関数は次のテクノロジでサポートされています。
| テクノロジ | サポート |
|---|---|
| Server Message Block (SMB) 3.0 プロトコル | いいえ |
| SMB 3.0 Transparent Failover (TFO) | いいえ |
| SMB 3.0 with Scale-out File Shares (SO) | いいえ |
| Cluster Shared Volume File System (CsvFS) | はい |
| Resilient File System (ReFS) | いいえ |
例
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0501
#ifdef NTDDI_VERSION
#undef NTDDI_VERSION
#endif
#define NTDDI_VERSION 0x05010000
#include <Windows.h>
void main()
{
HANDLE hFile = INVALID_HANDLE_VALUE;
// Disable redirection immediately prior to the native API
// function call.
if( Wow64EnableWow64FsRedirection(FALSE) )
{
// Any function calls in this block of code should be as concise
// and as simple as possible to avoid unintended results.
hFile = CreateFile(TEXT("C:\\Windows\\System32\\Notepad.exe"),
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
// Immediately re-enable redirection. Note that any resources
// associated with OldValue are cleaned up by this call.
if ( FALSE == Wow64EnableWow64FsRedirection(TRUE) )
{
// Failure to re-enable redirection should be considered
// a critical failure and execution aborted.
return;
}
}
// The handle, if valid, can be used as usual without
// leaving redirection disabled.
if( INVALID_HANDLE_VALUE != hFile )
{
// Use the file handle
}
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOLEAN Wow64EnableWow64FsRedirection(
BOOLEAN Wow64FsEnableRedirection
);[return: MarshalAs(UnmanagedType.U1)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool Wow64EnableWow64FsRedirection(
[MarshalAs(UnmanagedType.U1)] bool Wow64FsEnableRedirection // BOOLEAN
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function Wow64EnableWow64FsRedirection(
<MarshalAs(UnmanagedType.U1)> Wow64FsEnableRedirection As Boolean ' BOOLEAN
) As <MarshalAs(UnmanagedType.U1)> Boolean
End Function' Wow64FsEnableRedirection : BOOLEAN
Declare PtrSafe Function Wow64EnableWow64FsRedirection Lib "kernel32" ( _
ByVal Wow64FsEnableRedirection As Byte) As Byte
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
Wow64EnableWow64FsRedirection = ctypes.windll.kernel32.Wow64EnableWow64FsRedirection
Wow64EnableWow64FsRedirection.restype = wintypes.BOOLEAN
Wow64EnableWow64FsRedirection.argtypes = [
wintypes.BOOLEAN, # Wow64FsEnableRedirection : BOOLEAN
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
Wow64EnableWow64FsRedirection = Fiddle::Function.new(
lib['Wow64EnableWow64FsRedirection'],
[
Fiddle::TYPE_CHAR, # Wow64FsEnableRedirection : BOOLEAN
],
Fiddle::TYPE_CHAR)#[link(name = "kernel32")]
extern "system" {
fn Wow64EnableWow64FsRedirection(
Wow64FsEnableRedirection: u8 // BOOLEAN
) -> u8;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.U1)]
[DllImport("KERNEL32.dll")]
public static extern bool Wow64EnableWow64FsRedirection([MarshalAs(UnmanagedType.U1)] bool Wow64FsEnableRedirection);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_Wow64EnableWow64FsRedirection' -Namespace Win32 -PassThru
# $api::Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection)#uselib "KERNEL32.dll"
#func global Wow64EnableWow64FsRedirection "Wow64EnableWow64FsRedirection" sptr
; Wow64EnableWow64FsRedirection Wow64FsEnableRedirection ; 戻り値は stat
; Wow64FsEnableRedirection : BOOLEAN -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global Wow64EnableWow64FsRedirection "Wow64EnableWow64FsRedirection" int
; res = Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection)
; Wow64FsEnableRedirection : BOOLEAN -> "int"; BOOLEAN Wow64EnableWow64FsRedirection(BOOLEAN Wow64FsEnableRedirection)
#uselib "KERNEL32.dll"
#cfunc global Wow64EnableWow64FsRedirection "Wow64EnableWow64FsRedirection" int
; res = Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection)
; Wow64FsEnableRedirection : BOOLEAN -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procWow64EnableWow64FsRedirection = kernel32.NewProc("Wow64EnableWow64FsRedirection")
)
// Wow64FsEnableRedirection (BOOLEAN)
r1, _, err := procWow64EnableWow64FsRedirection.Call(
uintptr(Wow64FsEnableRedirection),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLEANfunction Wow64EnableWow64FsRedirection(
Wow64FsEnableRedirection: ByteBool // BOOLEAN
): ByteBool; stdcall;
external 'KERNEL32.dll' name 'Wow64EnableWow64FsRedirection';result := DllCall("KERNEL32\Wow64EnableWow64FsRedirection"
, "Char", Wow64FsEnableRedirection ; BOOLEAN
, "Char") ; return: BOOLEAN●Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection) = DLL("KERNEL32.dll", "byte Wow64EnableWow64FsRedirection(byte)")
# 呼び出し: Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection)
# Wow64FsEnableRedirection : BOOLEAN -> "byte"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn Wow64EnableWow64FsRedirection(
Wow64FsEnableRedirection: u8 // BOOLEAN
) callconv(std.os.windows.WINAPI) u8;proc Wow64EnableWow64FsRedirection(
Wow64FsEnableRedirection: uint8 # BOOLEAN
): uint8 {.importc: "Wow64EnableWow64FsRedirection", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
ubyte Wow64EnableWow64FsRedirection(
ubyte Wow64FsEnableRedirection // BOOLEAN
);ccall((:Wow64EnableWow64FsRedirection, "KERNEL32.dll"), stdcall, UInt8,
(UInt8,),
Wow64FsEnableRedirection)
# Wow64FsEnableRedirection : BOOLEAN -> UInt8
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint8_t Wow64EnableWow64FsRedirection(
uint8_t Wow64FsEnableRedirection);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection)
-- Wow64FsEnableRedirection : BOOLEAN
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const Wow64EnableWow64FsRedirection = lib.func('__stdcall', 'Wow64EnableWow64FsRedirection', 'uint8_t', ['uint8_t']);
// Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection)
// Wow64FsEnableRedirection : BOOLEAN -> 'uint8_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
Wow64EnableWow64FsRedirection: { parameters: ["u8"], result: "u8" },
});
// lib.symbols.Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection)
// Wow64FsEnableRedirection : BOOLEAN -> "u8"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint8_t Wow64EnableWow64FsRedirection(
uint8_t Wow64FsEnableRedirection);
C, "KERNEL32.dll");
// $ffi->Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection);
// Wow64FsEnableRedirection : BOOLEAN
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
byte Wow64EnableWow64FsRedirection(
byte Wow64FsEnableRedirection // BOOLEAN
);
}@[Link("kernel32")]
lib LibKERNEL32
fun Wow64EnableWow64FsRedirection = Wow64EnableWow64FsRedirection(
Wow64FsEnableRedirection : UInt8 # BOOLEAN
) : UInt8
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef Wow64EnableWow64FsRedirectionNative = Uint8 Function(Uint8);
typedef Wow64EnableWow64FsRedirectionDart = int Function(int);
final Wow64EnableWow64FsRedirection = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<Wow64EnableWow64FsRedirectionNative, Wow64EnableWow64FsRedirectionDart>('Wow64EnableWow64FsRedirection');
// Wow64FsEnableRedirection : BOOLEAN -> Uint8
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function Wow64EnableWow64FsRedirection(
Wow64FsEnableRedirection: ByteBool // BOOLEAN
): ByteBool; stdcall;
external 'KERNEL32.dll' name 'Wow64EnableWow64FsRedirection';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "Wow64EnableWow64FsRedirection"
c_Wow64EnableWow64FsRedirection :: Word8 -> IO Word8
-- Wow64FsEnableRedirection : BOOLEAN -> Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wow64enablewow64fsredirection =
foreign "Wow64EnableWow64FsRedirection"
(uint8_t @-> returning uint8_t)
(* Wow64FsEnableRedirection : BOOLEAN -> uint8_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("Wow64EnableWow64FsRedirection" wow64-enable-wow64-fs-redirection :convention :stdcall) :uint8
(wow64-fs-enable-redirection :uint8)) ; BOOLEAN
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $Wow64EnableWow64FsRedirection = Win32::API::More->new('KERNEL32',
'BYTE Wow64EnableWow64FsRedirection(BYTE Wow64FsEnableRedirection)');
# my $ret = $Wow64EnableWow64FsRedirection->Call($Wow64FsEnableRedirection);
# Wow64FsEnableRedirection : BOOLEAN -> BYTE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetSystemWow64DirectoryW — WOW64用システムディレクトリのパスを取得する(Unicode版)。
- f Wow64DisableWow64FsRedirection — WOW64のファイルシステムリダイレクトを無効化し旧状態を保存する。
- f Wow64RevertWow64FsRedirection — WOW64ファイルシステムリダイレクトを保存済み状態へ復元する。