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

GetMachineTypeAttributes

関数
指定マシンタイプの実行可能属性を取得する。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

HRESULT GetMachineTypeAttributes(
    WORD Machine,
    MACHINE_ATTRIBUTES* MachineTypeAttributes
);

パラメーター

名前方向説明
MachineWORDinサポート状況をテストするコードのアーキテクチャに対応する IMAGE_FILE_MACHINE_* 値。アーキテクチャ値の一覧については、Image File Machine Constants を参照してください。
MachineTypeAttributesMACHINE_ATTRIBUTES*out出力パラメーター。指定したコードアーキテクチャがホストオペレーティングシステム上でユーザーモード、カーネルモード、および/または WOW64 のもとで実行できるかどうかを示す、MACHINE_ATTRIBUTES 列挙体の値へのポインターを受け取ります。

戻り値の型: HRESULT

公式ドキュメント

指定したアーキテクチャが、ネイティブに、または何らかの互換レイヤーやエミュレーションレイヤーを介して、現在のシステムでサポートされているかどうかを照会します。

戻り値

関数が失敗した場合、戻り値は 0 以外の HRESULT 値です。関数が成功した場合、戻り値は 0 です。

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

各言語での呼び出し定義

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

HRESULT GetMachineTypeAttributes(
    WORD Machine,
    MACHINE_ATTRIBUTES* MachineTypeAttributes
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern int GetMachineTypeAttributes(
    ushort Machine,   // WORD
    out int MachineTypeAttributes   // MACHINE_ATTRIBUTES* out
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function GetMachineTypeAttributes(
    Machine As UShort,   ' WORD
    <Out> ByRef MachineTypeAttributes As Integer   ' MACHINE_ATTRIBUTES* out
) As Integer
End Function
' Machine : WORD
' MachineTypeAttributes : MACHINE_ATTRIBUTES* out
Declare PtrSafe Function GetMachineTypeAttributes Lib "kernel32" ( _
    ByVal Machine As Integer, _
    ByRef MachineTypeAttributes As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetMachineTypeAttributes = ctypes.windll.kernel32.GetMachineTypeAttributes
GetMachineTypeAttributes.restype = ctypes.c_int
GetMachineTypeAttributes.argtypes = [
    ctypes.c_ushort,  # Machine : WORD
    ctypes.c_void_p,  # MachineTypeAttributes : MACHINE_ATTRIBUTES* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetMachineTypeAttributes = Fiddle::Function.new(
  lib['GetMachineTypeAttributes'],
  [
    -Fiddle::TYPE_SHORT,  # Machine : WORD
    Fiddle::TYPE_VOIDP,  # MachineTypeAttributes : MACHINE_ATTRIBUTES* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetMachineTypeAttributes(
        Machine: u16,  // WORD
        MachineTypeAttributes: *mut i32  // MACHINE_ATTRIBUTES* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern int GetMachineTypeAttributes(ushort Machine, out int MachineTypeAttributes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetMachineTypeAttributes' -Namespace Win32 -PassThru
# $api::GetMachineTypeAttributes(Machine, MachineTypeAttributes)
#uselib "KERNEL32.dll"
#func global GetMachineTypeAttributes "GetMachineTypeAttributes" sptr, sptr
; GetMachineTypeAttributes Machine, varptr(MachineTypeAttributes)   ; 戻り値は stat
; Machine : WORD -> "sptr"
; MachineTypeAttributes : MACHINE_ATTRIBUTES* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetMachineTypeAttributes "GetMachineTypeAttributes" int, var
; res = GetMachineTypeAttributes(Machine, MachineTypeAttributes)
; Machine : WORD -> "int"
; MachineTypeAttributes : MACHINE_ATTRIBUTES* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT GetMachineTypeAttributes(WORD Machine, MACHINE_ATTRIBUTES* MachineTypeAttributes)
#uselib "KERNEL32.dll"
#cfunc global GetMachineTypeAttributes "GetMachineTypeAttributes" int, var
; res = GetMachineTypeAttributes(Machine, MachineTypeAttributes)
; Machine : WORD -> "int"
; MachineTypeAttributes : MACHINE_ATTRIBUTES* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetMachineTypeAttributes = kernel32.NewProc("GetMachineTypeAttributes")
)

// Machine (WORD), MachineTypeAttributes (MACHINE_ATTRIBUTES* out)
r1, _, err := procGetMachineTypeAttributes.Call(
	uintptr(Machine),
	uintptr(MachineTypeAttributes),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function GetMachineTypeAttributes(
  Machine: Word;   // WORD
  MachineTypeAttributes: Pointer   // MACHINE_ATTRIBUTES* out
): Integer; stdcall;
  external 'KERNEL32.dll' name 'GetMachineTypeAttributes';
result := DllCall("KERNEL32\GetMachineTypeAttributes"
    , "UShort", Machine   ; WORD
    , "Ptr", MachineTypeAttributes   ; MACHINE_ATTRIBUTES* out
    , "Int")   ; return: HRESULT
●GetMachineTypeAttributes(Machine, MachineTypeAttributes) = DLL("KERNEL32.dll", "int GetMachineTypeAttributes(int, void*)")
# 呼び出し: GetMachineTypeAttributes(Machine, MachineTypeAttributes)
# Machine : WORD -> "int"
# MachineTypeAttributes : MACHINE_ATTRIBUTES* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef GetMachineTypeAttributesNative = Int32 Function(Uint16, Pointer<Int32>);
typedef GetMachineTypeAttributesDart = int Function(int, Pointer<Int32>);
final GetMachineTypeAttributes = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<GetMachineTypeAttributesNative, GetMachineTypeAttributesDart>('GetMachineTypeAttributes');
// Machine : WORD -> Uint16
// MachineTypeAttributes : MACHINE_ATTRIBUTES* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetMachineTypeAttributes(
  Machine: Word;   // WORD
  MachineTypeAttributes: Pointer   // MACHINE_ATTRIBUTES* out
): Integer; stdcall;
  external 'KERNEL32.dll' name 'GetMachineTypeAttributes';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetMachineTypeAttributes"
  c_GetMachineTypeAttributes :: Word16 -> Ptr Int32 -> IO Int32
-- Machine : WORD -> Word16
-- MachineTypeAttributes : MACHINE_ATTRIBUTES* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getmachinetypeattributes =
  foreign "GetMachineTypeAttributes"
    (uint16_t @-> (ptr int32_t) @-> returning int32_t)
(* Machine : WORD -> uint16_t *)
(* MachineTypeAttributes : MACHINE_ATTRIBUTES* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("GetMachineTypeAttributes" get-machine-type-attributes :convention :stdcall) :int32
  (machine :uint16)   ; WORD
  (machine-type-attributes :pointer))   ; MACHINE_ATTRIBUTES* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetMachineTypeAttributes = Win32::API::More->new('KERNEL32',
    'int GetMachineTypeAttributes(WORD Machine, LPVOID MachineTypeAttributes)');
# my $ret = $GetMachineTypeAttributes->Call($Machine, $MachineTypeAttributes);
# Machine : WORD -> WORD
# MachineTypeAttributes : MACHINE_ATTRIBUTES* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型