Win32 API 日本語リファレンス
ホームSecurity.AppLocker › SaferiIsExecutableFileType

SaferiIsExecutableFileType

関数
指定パスのファイルが実行可能ファイル種別かどうかを判定する。
DLLADVAPI32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

BOOL SaferiIsExecutableFileType(
    LPCWSTR szFullPathname,
    BOOLEAN bFromShellExecute
);

パラメーター

名前方向説明
szFullPathnameLPCWSTRin実行可能ファイル種別か判定する対象のフルパスのワイド文字列。
bFromShellExecuteBOOLEANinShellExecute経由の呼び出しかを示すブール値。判定基準に影響する。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SaferiIsExecutableFileType(
    LPCWSTR szFullPathname,
    BOOLEAN bFromShellExecute
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern bool SaferiIsExecutableFileType(
    [MarshalAs(UnmanagedType.LPWStr)] string szFullPathname,   // LPCWSTR
    [MarshalAs(UnmanagedType.U1)] bool bFromShellExecute   // BOOLEAN
);
<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function SaferiIsExecutableFileType(
    <MarshalAs(UnmanagedType.LPWStr)> szFullPathname As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.U1)> bFromShellExecute As Boolean   ' BOOLEAN
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' szFullPathname : LPCWSTR
' bFromShellExecute : BOOLEAN
Declare PtrSafe Function SaferiIsExecutableFileType Lib "advapi32" ( _
    ByVal szFullPathname As LongPtr, _
    ByVal bFromShellExecute As Byte) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SaferiIsExecutableFileType = ctypes.windll.advapi32.SaferiIsExecutableFileType
SaferiIsExecutableFileType.restype = wintypes.BOOL
SaferiIsExecutableFileType.argtypes = [
    wintypes.LPCWSTR,  # szFullPathname : LPCWSTR
    wintypes.BOOLEAN,  # bFromShellExecute : BOOLEAN
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
SaferiIsExecutableFileType = Fiddle::Function.new(
  lib['SaferiIsExecutableFileType'],
  [
    Fiddle::TYPE_VOIDP,  # szFullPathname : LPCWSTR
    Fiddle::TYPE_CHAR,  # bFromShellExecute : BOOLEAN
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn SaferiIsExecutableFileType(
        szFullPathname: *const u16,  // LPCWSTR
        bFromShellExecute: u8  // BOOLEAN
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll")]
public static extern bool SaferiIsExecutableFileType([MarshalAs(UnmanagedType.LPWStr)] string szFullPathname, [MarshalAs(UnmanagedType.U1)] bool bFromShellExecute);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SaferiIsExecutableFileType' -Namespace Win32 -PassThru
# $api::SaferiIsExecutableFileType(szFullPathname, bFromShellExecute)
#uselib "ADVAPI32.dll"
#func global SaferiIsExecutableFileType "SaferiIsExecutableFileType" sptr, sptr
; SaferiIsExecutableFileType szFullPathname, bFromShellExecute   ; 戻り値は stat
; szFullPathname : LPCWSTR -> "sptr"
; bFromShellExecute : BOOLEAN -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global SaferiIsExecutableFileType "SaferiIsExecutableFileType" wstr, int
; res = SaferiIsExecutableFileType(szFullPathname, bFromShellExecute)
; szFullPathname : LPCWSTR -> "wstr"
; bFromShellExecute : BOOLEAN -> "int"
; BOOL SaferiIsExecutableFileType(LPCWSTR szFullPathname, BOOLEAN bFromShellExecute)
#uselib "ADVAPI32.dll"
#cfunc global SaferiIsExecutableFileType "SaferiIsExecutableFileType" wstr, int
; res = SaferiIsExecutableFileType(szFullPathname, bFromShellExecute)
; szFullPathname : LPCWSTR -> "wstr"
; bFromShellExecute : BOOLEAN -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procSaferiIsExecutableFileType = advapi32.NewProc("SaferiIsExecutableFileType")
)

// szFullPathname (LPCWSTR), bFromShellExecute (BOOLEAN)
r1, _, err := procSaferiIsExecutableFileType.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szFullPathname))),
	uintptr(bFromShellExecute),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SaferiIsExecutableFileType(
  szFullPathname: PWideChar;   // LPCWSTR
  bFromShellExecute: ByteBool   // BOOLEAN
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'SaferiIsExecutableFileType';
result := DllCall("ADVAPI32\SaferiIsExecutableFileType"
    , "WStr", szFullPathname   ; LPCWSTR
    , "Char", bFromShellExecute   ; BOOLEAN
    , "Int")   ; return: BOOL
●SaferiIsExecutableFileType(szFullPathname, bFromShellExecute) = DLL("ADVAPI32.dll", "bool SaferiIsExecutableFileType(char*, byte)")
# 呼び出し: SaferiIsExecutableFileType(szFullPathname, bFromShellExecute)
# szFullPathname : LPCWSTR -> "char*"
# bFromShellExecute : BOOLEAN -> "byte"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef SaferiIsExecutableFileTypeNative = Int32 Function(Pointer<Utf16>, Uint8);
typedef SaferiIsExecutableFileTypeDart = int Function(Pointer<Utf16>, int);
final SaferiIsExecutableFileType = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<SaferiIsExecutableFileTypeNative, SaferiIsExecutableFileTypeDart>('SaferiIsExecutableFileType');
// szFullPathname : LPCWSTR -> Pointer<Utf16>
// bFromShellExecute : BOOLEAN -> Uint8
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SaferiIsExecutableFileType(
  szFullPathname: PWideChar;   // LPCWSTR
  bFromShellExecute: ByteBool   // BOOLEAN
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'SaferiIsExecutableFileType';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SaferiIsExecutableFileType"
  c_SaferiIsExecutableFileType :: CWString -> Word8 -> IO CInt
-- szFullPathname : LPCWSTR -> CWString
-- bFromShellExecute : BOOLEAN -> Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let saferiisexecutablefiletype =
  foreign "SaferiIsExecutableFileType"
    ((ptr uint16_t) @-> uint8_t @-> returning int32_t)
(* szFullPathname : LPCWSTR -> (ptr uint16_t) *)
(* bFromShellExecute : BOOLEAN -> uint8_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("SaferiIsExecutableFileType" saferi-is-executable-file-type :convention :stdcall) :int32
  (sz-full-pathname (:string :encoding :utf-16le))   ; LPCWSTR
  (b-from-shell-execute :uint8))   ; BOOLEAN
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SaferiIsExecutableFileType = Win32::API::More->new('ADVAPI32',
    'BOOL SaferiIsExecutableFileType(LPCWSTR szFullPathname, BYTE bFromShellExecute)');
# my $ret = $SaferiIsExecutableFileType->Call($szFullPathname, $bFromShellExecute);
# szFullPathname : LPCWSTR -> LPCWSTR
# bFromShellExecute : BOOLEAN -> BYTE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。