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

GetSystemWow64DirectoryA

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

シグネチャ

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

DWORD GetSystemWow64DirectoryA(
    LPSTR lpBuffer,   // optional
    DWORD uSize
);

パラメーター

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

戻り値の型: DWORD

公式ドキュメント

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

戻り値

関数が成功した場合、戻り値はバッファにコピーされた文字列の長さ(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 ヘッダーは、GetSystemWow64Directory を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング中立のエイリアスを、エンコーディング中立でないコードと混在させて使用すると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

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

各言語での呼び出し定義

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

DWORD GetSystemWow64DirectoryA(
    LPSTR lpBuffer,   // optional
    DWORD uSize
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint GetSystemWow64DirectoryA(
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuffer,   // LPSTR optional, out
    uint uSize   // DWORD
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetSystemWow64DirectoryA(
    <MarshalAs(UnmanagedType.LPStr)> lpBuffer As System.Text.StringBuilder,   ' LPSTR optional, out
    uSize As UInteger   ' DWORD
) As UInteger
End Function
' lpBuffer : LPSTR optional, out
' uSize : DWORD
Declare PtrSafe Function GetSystemWow64DirectoryA Lib "kernel32" ( _
    ByVal lpBuffer As String, _
    ByVal uSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetSystemWow64DirectoryA = ctypes.windll.kernel32.GetSystemWow64DirectoryA
GetSystemWow64DirectoryA.restype = wintypes.DWORD
GetSystemWow64DirectoryA.argtypes = [
    wintypes.LPSTR,  # lpBuffer : LPSTR 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')
GetSystemWow64DirectoryA = Fiddle::Function.new(
  lib['GetSystemWow64DirectoryA'],
  [
    Fiddle::TYPE_VOIDP,  # lpBuffer : LPSTR optional, out
    -Fiddle::TYPE_INT,  # uSize : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetSystemWow64DirectoryA(
        lpBuffer: *mut u8,  // LPSTR optional, out
        uSize: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern uint GetSystemWow64DirectoryA([MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuffer, uint uSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetSystemWow64DirectoryA' -Namespace Win32 -PassThru
# $api::GetSystemWow64DirectoryA(lpBuffer, uSize)
#uselib "KERNEL32.dll"
#func global GetSystemWow64DirectoryA "GetSystemWow64DirectoryA" sptr, sptr
; GetSystemWow64DirectoryA varptr(lpBuffer), uSize   ; 戻り値は stat
; lpBuffer : LPSTR optional, out -> "sptr"
; uSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetSystemWow64DirectoryA "GetSystemWow64DirectoryA" var, int
; res = GetSystemWow64DirectoryA(lpBuffer, uSize)
; lpBuffer : LPSTR optional, out -> "var"
; uSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetSystemWow64DirectoryA(LPSTR lpBuffer, DWORD uSize)
#uselib "KERNEL32.dll"
#cfunc global GetSystemWow64DirectoryA "GetSystemWow64DirectoryA" var, int
; res = GetSystemWow64DirectoryA(lpBuffer, uSize)
; lpBuffer : LPSTR optional, out -> "var"
; uSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetSystemWow64DirectoryA = kernel32.NewProc("GetSystemWow64DirectoryA")
)

// lpBuffer (LPSTR optional, out), uSize (DWORD)
r1, _, err := procGetSystemWow64DirectoryA.Call(
	uintptr(lpBuffer),
	uintptr(uSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetSystemWow64DirectoryA(
  lpBuffer: PAnsiChar;   // LPSTR optional, out
  uSize: DWORD   // DWORD
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'GetSystemWow64DirectoryA';
result := DllCall("KERNEL32\GetSystemWow64DirectoryA"
    , "Ptr", lpBuffer   ; LPSTR optional, out
    , "UInt", uSize   ; DWORD
    , "UInt")   ; return: DWORD
●GetSystemWow64DirectoryA(lpBuffer, uSize) = DLL("KERNEL32.dll", "dword GetSystemWow64DirectoryA(char*, dword)")
# 呼び出し: GetSystemWow64DirectoryA(lpBuffer, uSize)
# lpBuffer : LPSTR optional, out -> "char*"
# uSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn GetSystemWow64DirectoryA(
    lpBuffer: [*c]u8, // LPSTR optional, out
    uSize: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc GetSystemWow64DirectoryA(
    lpBuffer: ptr char,  # LPSTR optional, out
    uSize: uint32  # DWORD
): uint32 {.importc: "GetSystemWow64DirectoryA", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
uint GetSystemWow64DirectoryA(
    char* lpBuffer,   // LPSTR optional, out
    uint uSize   // DWORD
);
ccall((:GetSystemWow64DirectoryA, "KERNEL32.dll"), stdcall, UInt32,
      (Ptr{UInt8}, UInt32),
      lpBuffer, uSize)
# lpBuffer : LPSTR optional, out -> Ptr{UInt8}
# uSize : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t GetSystemWow64DirectoryA(
    char* lpBuffer,
    uint32_t uSize);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetSystemWow64DirectoryA(lpBuffer, uSize)
-- lpBuffer : LPSTR optional, out
-- uSize : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetSystemWow64DirectoryA = lib.func('__stdcall', 'GetSystemWow64DirectoryA', 'uint32_t', ['char *', 'uint32_t']);
// GetSystemWow64DirectoryA(lpBuffer, uSize)
// lpBuffer : LPSTR optional, out -> 'char *'
// uSize : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  GetSystemWow64DirectoryA: { parameters: ["buffer", "u32"], result: "u32" },
});
// lib.symbols.GetSystemWow64DirectoryA(lpBuffer, uSize)
// lpBuffer : LPSTR optional, out -> "buffer"
// uSize : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t GetSystemWow64DirectoryA(
    char* lpBuffer,
    uint32_t uSize);
C, "KERNEL32.dll");
// $ffi->GetSystemWow64DirectoryA(lpBuffer, uSize);
// lpBuffer : LPSTR 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.ASCII_OPTIONS);
    int GetSystemWow64DirectoryA(
        byte[] lpBuffer,   // LPSTR optional, out
        int uSize   // DWORD
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun GetSystemWow64DirectoryA = GetSystemWow64DirectoryA(
    lpBuffer : UInt8*,   # LPSTR 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 GetSystemWow64DirectoryANative = Uint32 Function(Pointer<Utf8>, Uint32);
typedef GetSystemWow64DirectoryADart = int Function(Pointer<Utf8>, int);
final GetSystemWow64DirectoryA = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<GetSystemWow64DirectoryANative, GetSystemWow64DirectoryADart>('GetSystemWow64DirectoryA');
// lpBuffer : LPSTR optional, out -> Pointer<Utf8>
// uSize : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetSystemWow64DirectoryA(
  lpBuffer: PAnsiChar;   // LPSTR optional, out
  uSize: DWORD   // DWORD
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'GetSystemWow64DirectoryA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let getsystemwow64directorya =
  foreign "GetSystemWow64DirectoryA"
    (string @-> uint32_t @-> returning uint32_t)
(* lpBuffer : LPSTR optional, out -> string *)
(* 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 ("GetSystemWow64DirectoryA" get-system-wow64-directory-a :convention :stdcall) :uint32
  (lp-buffer :pointer)   ; LPSTR optional, out
  (u-size :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetSystemWow64DirectoryA = Win32::API::More->new('KERNEL32',
    'DWORD GetSystemWow64DirectoryA(LPSTR lpBuffer, DWORD uSize)');
# my $ret = $GetSystemWow64DirectoryA->Call($lpBuffer, $uSize);
# lpBuffer : LPSTR optional, out -> LPSTR
# uSize : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
類似 API