Win32 API 日本語リファレンス
ホームStorage.FileSystem › GetBinaryTypeA

GetBinaryTypeA

関数
実行可能ファイルのバイナリ種別を判定する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL GetBinaryTypeA(
    LPCSTR lpApplicationName,
    DWORD* lpBinaryType
);

パラメーター

名前方向
lpApplicationNameLPCSTRin
lpBinaryTypeDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetBinaryTypeA(
    LPCSTR lpApplicationName,
    DWORD* lpBinaryType
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool GetBinaryTypeA(
    [MarshalAs(UnmanagedType.LPStr)] string lpApplicationName,   // LPCSTR
    out uint lpBinaryType   // DWORD* out
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetBinaryTypeA(
    <MarshalAs(UnmanagedType.LPStr)> lpApplicationName As String,   ' LPCSTR
    <Out> ByRef lpBinaryType As UInteger   ' DWORD* out
) As Boolean
End Function
' lpApplicationName : LPCSTR
' lpBinaryType : DWORD* out
Declare PtrSafe Function GetBinaryTypeA Lib "kernel32" ( _
    ByVal lpApplicationName As String, _
    ByRef lpBinaryType As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetBinaryTypeA = ctypes.windll.kernel32.GetBinaryTypeA
GetBinaryTypeA.restype = wintypes.BOOL
GetBinaryTypeA.argtypes = [
    wintypes.LPCSTR,  # lpApplicationName : LPCSTR
    ctypes.POINTER(wintypes.DWORD),  # lpBinaryType : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetBinaryTypeA = Fiddle::Function.new(
  lib['GetBinaryTypeA'],
  [
    Fiddle::TYPE_VOIDP,  # lpApplicationName : LPCSTR
    Fiddle::TYPE_VOIDP,  # lpBinaryType : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetBinaryTypeA(
        lpApplicationName: *const u8,  // LPCSTR
        lpBinaryType: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool GetBinaryTypeA([MarshalAs(UnmanagedType.LPStr)] string lpApplicationName, out uint lpBinaryType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetBinaryTypeA' -Namespace Win32 -PassThru
# $api::GetBinaryTypeA(lpApplicationName, lpBinaryType)
#uselib "KERNEL32.dll"
#func global GetBinaryTypeA "GetBinaryTypeA" sptr, sptr
; GetBinaryTypeA lpApplicationName, varptr(lpBinaryType)   ; 戻り値は stat
; lpApplicationName : LPCSTR -> "sptr"
; lpBinaryType : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetBinaryTypeA "GetBinaryTypeA" str, var
; res = GetBinaryTypeA(lpApplicationName, lpBinaryType)
; lpApplicationName : LPCSTR -> "str"
; lpBinaryType : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetBinaryTypeA(LPCSTR lpApplicationName, DWORD* lpBinaryType)
#uselib "KERNEL32.dll"
#cfunc global GetBinaryTypeA "GetBinaryTypeA" str, var
; res = GetBinaryTypeA(lpApplicationName, lpBinaryType)
; lpApplicationName : LPCSTR -> "str"
; lpBinaryType : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetBinaryTypeA = kernel32.NewProc("GetBinaryTypeA")
)

// lpApplicationName (LPCSTR), lpBinaryType (DWORD* out)
r1, _, err := procGetBinaryTypeA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpApplicationName))),
	uintptr(lpBinaryType),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetBinaryTypeA(
  lpApplicationName: PAnsiChar;   // LPCSTR
  lpBinaryType: Pointer   // DWORD* out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'GetBinaryTypeA';
result := DllCall("KERNEL32\GetBinaryTypeA"
    , "AStr", lpApplicationName   ; LPCSTR
    , "Ptr", lpBinaryType   ; DWORD* out
    , "Int")   ; return: BOOL
●GetBinaryTypeA(lpApplicationName, lpBinaryType) = DLL("KERNEL32.dll", "bool GetBinaryTypeA(char*, void*)")
# 呼び出し: GetBinaryTypeA(lpApplicationName, lpBinaryType)
# lpApplicationName : LPCSTR -> "char*"
# lpBinaryType : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。