ホーム › Storage.FileSystem › GetBinaryTypeW
GetBinaryTypeW
関数実行可能ファイルのバイナリ種別を判定する(Unicode版)。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL GetBinaryTypeW(
LPCWSTR lpApplicationName,
DWORD* lpBinaryType
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpApplicationName | LPCWSTR | in |
| lpBinaryType | DWORD* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL GetBinaryTypeW(
LPCWSTR lpApplicationName,
DWORD* lpBinaryType
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool GetBinaryTypeW(
[MarshalAs(UnmanagedType.LPWStr)] string lpApplicationName, // LPCWSTR
out uint lpBinaryType // DWORD* out
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetBinaryTypeW(
<MarshalAs(UnmanagedType.LPWStr)> lpApplicationName As String, ' LPCWSTR
<Out> ByRef lpBinaryType As UInteger ' DWORD* out
) As Boolean
End Function' lpApplicationName : LPCWSTR
' lpBinaryType : DWORD* out
Declare PtrSafe Function GetBinaryTypeW Lib "kernel32" ( _
ByVal lpApplicationName As LongPtr, _
ByRef lpBinaryType 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
GetBinaryTypeW = ctypes.windll.kernel32.GetBinaryTypeW
GetBinaryTypeW.restype = wintypes.BOOL
GetBinaryTypeW.argtypes = [
wintypes.LPCWSTR, # lpApplicationName : LPCWSTR
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')
GetBinaryTypeW = Fiddle::Function.new(
lib['GetBinaryTypeW'],
[
Fiddle::TYPE_VOIDP, # lpApplicationName : LPCWSTR
Fiddle::TYPE_VOIDP, # lpBinaryType : DWORD* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn GetBinaryTypeW(
lpApplicationName: *const u16, // LPCWSTR
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.Unicode, SetLastError = true)]
public static extern bool GetBinaryTypeW([MarshalAs(UnmanagedType.LPWStr)] string lpApplicationName, out uint lpBinaryType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetBinaryTypeW' -Namespace Win32 -PassThru
# $api::GetBinaryTypeW(lpApplicationName, lpBinaryType)#uselib "KERNEL32.dll"
#func global GetBinaryTypeW "GetBinaryTypeW" wptr, wptr
; GetBinaryTypeW lpApplicationName, varptr(lpBinaryType) ; 戻り値は stat
; lpApplicationName : LPCWSTR -> "wptr"
; lpBinaryType : DWORD* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global GetBinaryTypeW "GetBinaryTypeW" wstr, var ; res = GetBinaryTypeW(lpApplicationName, lpBinaryType) ; lpApplicationName : LPCWSTR -> "wstr" ; lpBinaryType : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetBinaryTypeW "GetBinaryTypeW" wstr, sptr ; res = GetBinaryTypeW(lpApplicationName, varptr(lpBinaryType)) ; lpApplicationName : LPCWSTR -> "wstr" ; lpBinaryType : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetBinaryTypeW(LPCWSTR lpApplicationName, DWORD* lpBinaryType) #uselib "KERNEL32.dll" #cfunc global GetBinaryTypeW "GetBinaryTypeW" wstr, var ; res = GetBinaryTypeW(lpApplicationName, lpBinaryType) ; lpApplicationName : LPCWSTR -> "wstr" ; lpBinaryType : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetBinaryTypeW(LPCWSTR lpApplicationName, DWORD* lpBinaryType) #uselib "KERNEL32.dll" #cfunc global GetBinaryTypeW "GetBinaryTypeW" wstr, intptr ; res = GetBinaryTypeW(lpApplicationName, varptr(lpBinaryType)) ; lpApplicationName : LPCWSTR -> "wstr" ; lpBinaryType : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetBinaryTypeW = kernel32.NewProc("GetBinaryTypeW")
)
// lpApplicationName (LPCWSTR), lpBinaryType (DWORD* out)
r1, _, err := procGetBinaryTypeW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpApplicationName))),
uintptr(lpBinaryType),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetBinaryTypeW(
lpApplicationName: PWideChar; // LPCWSTR
lpBinaryType: Pointer // DWORD* out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'GetBinaryTypeW';result := DllCall("KERNEL32\GetBinaryTypeW"
, "WStr", lpApplicationName ; LPCWSTR
, "Ptr", lpBinaryType ; DWORD* out
, "Int") ; return: BOOL●GetBinaryTypeW(lpApplicationName, lpBinaryType) = DLL("KERNEL32.dll", "bool GetBinaryTypeW(char*, void*)")
# 呼び出し: GetBinaryTypeW(lpApplicationName, lpBinaryType)
# lpApplicationName : LPCWSTR -> "char*"
# lpBinaryType : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。