Win32 API 日本語リファレンス
ホームSystem.SystemInformation › GetSystemWow64DirectoryW

GetSystemWow64DirectoryW

関数
WOW64用システムディレクトリのパスを取得する(Unicode版)。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

DWORD GetSystemWow64DirectoryW(
    LPWSTR lpBuffer,   // optional
    DWORD uSize
);

パラメーター

名前方向説明
lpBufferLPWSTRoutoptionalパスを受け取るバッファへのポインターです。このパスの末尾にバックスラッシュは付きません。
uSizeDWORDinバッファの最大サイズ(TCHAR 単位)です。

戻り値の型: DWORD

公式ドキュメント

WOW64 が使用するシステムディレクトリのパスを取得します。(Unicode)

戻り値

関数が成功した場合、戻り値はバッファにコピーされた文字列の長さ(TCHAR 単位)で、終端の null 文字は含みません。長さがバッファのサイズより大きい場合、戻り値はパスを格納するために必要なバッファのサイズです。

関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、 GetLastError を呼び出してください。

32 ビット版 Windows では、この関数は常に失敗し、拡張エラーには ERROR_CALL_NOT_IMPLEMENTED が設定されます。

解説(Remarks)

WOW64 は、64 ビット版 Windows 上で共有される 32 ビットコードを格納するためにシステムディレクトリを使用します。ほとんどのアプリケーションでは、このディレクトリに明示的にアクセスする必要はありません。

WOW64 の詳細については、 Running 32-bit Applications を参照してください。

この関数を使用するアプリケーションをコンパイルするには、_WIN32_WINNT を 0x0501 以降として定義してください。詳細については、 Using the Windows Headers を参照してください。

メモ

wow64apiset.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして GetSystemWow64Directory を定義しています。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、不一致が生じてコンパイルエラーや実行時エラーの原因となることがあります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

DWORD GetSystemWow64DirectoryW(
    LPWSTR lpBuffer,   // optional
    DWORD uSize
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern uint GetSystemWow64DirectoryW(
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpBuffer,   // LPWSTR optional, out
    uint uSize   // DWORD
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetSystemWow64DirectoryW(
    <MarshalAs(UnmanagedType.LPWStr)> lpBuffer As System.Text.StringBuilder,   ' LPWSTR optional, out
    uSize As UInteger   ' DWORD
) As UInteger
End Function
' lpBuffer : LPWSTR optional, out
' uSize : DWORD
Declare PtrSafe Function GetSystemWow64DirectoryW Lib "kernel32" ( _
    ByVal lpBuffer As LongPtr, _
    ByVal uSize As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetSystemWow64DirectoryW = ctypes.windll.kernel32.GetSystemWow64DirectoryW
GetSystemWow64DirectoryW.restype = wintypes.DWORD
GetSystemWow64DirectoryW.argtypes = [
    wintypes.LPWSTR,  # lpBuffer : LPWSTR optional, out
    wintypes.DWORD,  # uSize : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetSystemWow64DirectoryW = Fiddle::Function.new(
  lib['GetSystemWow64DirectoryW'],
  [
    Fiddle::TYPE_VOIDP,  # lpBuffer : LPWSTR optional, out
    -Fiddle::TYPE_INT,  # uSize : DWORD
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn GetSystemWow64DirectoryW(
        lpBuffer: *mut u16,  // LPWSTR optional, out
        uSize: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint GetSystemWow64DirectoryW([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpBuffer, uint uSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetSystemWow64DirectoryW' -Namespace Win32 -PassThru
# $api::GetSystemWow64DirectoryW(lpBuffer, uSize)
#uselib "KERNEL32.dll"
#func global GetSystemWow64DirectoryW "GetSystemWow64DirectoryW" wptr, wptr
; GetSystemWow64DirectoryW varptr(lpBuffer), uSize   ; 戻り値は stat
; lpBuffer : LPWSTR optional, out -> "wptr"
; uSize : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetSystemWow64DirectoryW "GetSystemWow64DirectoryW" var, int
; res = GetSystemWow64DirectoryW(lpBuffer, uSize)
; lpBuffer : LPWSTR optional, out -> "var"
; uSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetSystemWow64DirectoryW(LPWSTR lpBuffer, DWORD uSize)
#uselib "KERNEL32.dll"
#cfunc global GetSystemWow64DirectoryW "GetSystemWow64DirectoryW" var, int
; res = GetSystemWow64DirectoryW(lpBuffer, uSize)
; lpBuffer : LPWSTR optional, out -> "var"
; uSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetSystemWow64DirectoryW = kernel32.NewProc("GetSystemWow64DirectoryW")
)

// lpBuffer (LPWSTR optional, out), uSize (DWORD)
r1, _, err := procGetSystemWow64DirectoryW.Call(
	uintptr(lpBuffer),
	uintptr(uSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetSystemWow64DirectoryW(
  lpBuffer: PWideChar;   // LPWSTR optional, out
  uSize: DWORD   // DWORD
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'GetSystemWow64DirectoryW';
result := DllCall("KERNEL32\GetSystemWow64DirectoryW"
    , "Ptr", lpBuffer   ; LPWSTR optional, out
    , "UInt", uSize   ; DWORD
    , "UInt")   ; return: DWORD
●GetSystemWow64DirectoryW(lpBuffer, uSize) = DLL("KERNEL32.dll", "dword GetSystemWow64DirectoryW(char*, dword)")
# 呼び出し: GetSystemWow64DirectoryW(lpBuffer, uSize)
# lpBuffer : LPWSTR optional, out -> "char*"
# uSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "kernel32" fn GetSystemWow64DirectoryW(
    lpBuffer: [*c]u16, // LPWSTR optional, out
    uSize: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc GetSystemWow64DirectoryW(
    lpBuffer: ptr uint16,  # LPWSTR optional, out
    uSize: uint32  # DWORD
): uint32 {.importc: "GetSystemWow64DirectoryW", stdcall, dynlib: "KERNEL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "kernel32");
extern(Windows)
uint GetSystemWow64DirectoryW(
    wchar* lpBuffer,   // LPWSTR optional, out
    uint uSize   // DWORD
);
ccall((:GetSystemWow64DirectoryW, "KERNEL32.dll"), stdcall, UInt32,
      (Ptr{UInt16}, UInt32),
      lpBuffer, uSize)
# lpBuffer : LPWSTR optional, out -> Ptr{UInt16}
# uSize : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
uint32_t GetSystemWow64DirectoryW(
    uint16_t* lpBuffer,
    uint32_t uSize);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetSystemWow64DirectoryW(lpBuffer, uSize)
-- lpBuffer : LPWSTR optional, out
-- uSize : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetSystemWow64DirectoryW = lib.func('__stdcall', 'GetSystemWow64DirectoryW', 'uint32_t', ['uint16_t *', 'uint32_t']);
// GetSystemWow64DirectoryW(lpBuffer, uSize)
// lpBuffer : LPWSTR optional, out -> 'uint16_t *'
// uSize : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  GetSystemWow64DirectoryW: { parameters: ["buffer", "u32"], result: "u32" },
});
// lib.symbols.GetSystemWow64DirectoryW(lpBuffer, uSize)
// lpBuffer : LPWSTR optional, out -> "buffer"
// uSize : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t GetSystemWow64DirectoryW(
    uint16_t* lpBuffer,
    uint32_t uSize);
C, "KERNEL32.dll");
// $ffi->GetSystemWow64DirectoryW(lpBuffer, uSize);
// lpBuffer : LPWSTR optional, out
// uSize : 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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
    int GetSystemWow64DirectoryW(
        char[] lpBuffer,   // LPWSTR optional, out
        int uSize   // DWORD
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("kernel32")]
lib LibKERNEL32
  fun GetSystemWow64DirectoryW = GetSystemWow64DirectoryW(
    lpBuffer : UInt16*,   # LPWSTR optional, out
    uSize : UInt32   # DWORD
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetSystemWow64DirectoryWNative = Uint32 Function(Pointer<Utf16>, Uint32);
typedef GetSystemWow64DirectoryWDart = int Function(Pointer<Utf16>, int);
final GetSystemWow64DirectoryW = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<GetSystemWow64DirectoryWNative, GetSystemWow64DirectoryWDart>('GetSystemWow64DirectoryW');
// lpBuffer : LPWSTR optional, out -> Pointer<Utf16>
// uSize : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetSystemWow64DirectoryW(
  lpBuffer: PWideChar;   // LPWSTR optional, out
  uSize: DWORD   // DWORD
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'GetSystemWow64DirectoryW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetSystemWow64DirectoryW"
  c_GetSystemWow64DirectoryW :: CWString -> Word32 -> IO Word32
-- lpBuffer : LPWSTR optional, out -> CWString
-- uSize : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getsystemwow64directoryw =
  foreign "GetSystemWow64DirectoryW"
    ((ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* lpBuffer : LPWSTR optional, out -> (ptr uint16_t) *)
(* uSize : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("GetSystemWow64DirectoryW" get-system-wow64-directory-w :convention :stdcall) :uint32
  (lp-buffer :pointer)   ; LPWSTR optional, out
  (u-size :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetSystemWow64DirectoryW = Win32::API::More->new('KERNEL32',
    'DWORD GetSystemWow64DirectoryW(LPWSTR lpBuffer, DWORD uSize)');
# my $ret = $GetSystemWow64DirectoryW->Call($lpBuffer, $uSize);
# lpBuffer : LPWSTR optional, out -> LPWSTR
# uSize : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
類似 API