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

GetMachineTypeAttributes

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

シグネチャ

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

HRESULT GetMachineTypeAttributes(
    WORD Machine,
    MACHINE_ATTRIBUTES* MachineTypeAttributes
);

パラメーター

名前方向
MachineWORDin
MachineTypeAttributesMACHINE_ATTRIBUTES*out

戻り値の型: HRESULT

各言語での呼び出し定義

// 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, MachineTypeAttributes   ; 戻り値は stat
; Machine : WORD -> "sptr"
; MachineTypeAttributes : MACHINE_ATTRIBUTES* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global GetMachineTypeAttributes "GetMachineTypeAttributes" int, int
; res = GetMachineTypeAttributes(Machine, MachineTypeAttributes)
; Machine : WORD -> "int"
; MachineTypeAttributes : MACHINE_ATTRIBUTES* out -> "int"
; HRESULT GetMachineTypeAttributes(WORD Machine, MACHINE_ATTRIBUTES* MachineTypeAttributes)
#uselib "KERNEL32.dll"
#cfunc global GetMachineTypeAttributes "GetMachineTypeAttributes" int, int
; res = GetMachineTypeAttributes(Machine, MachineTypeAttributes)
; Machine : WORD -> "int"
; MachineTypeAttributes : MACHINE_ATTRIBUTES* out -> "int"
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)。