Win32 API 日本語リファレンス
ホームUI.Shell › PathMatchSpecExW

PathMatchSpecExW

関数
フラグ指定付きでファイル名がパターンに一致するか判定する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

HRESULT PathMatchSpecExW(
    LPCWSTR pszFile,
    LPCWSTR pszSpec,
    DWORD dwFlags
);

パラメーター

名前方向
pszFileLPCWSTRin
pszSpecLPCWSTRin
dwFlagsDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

HRESULT PathMatchSpecExW(
    LPCWSTR pszFile,
    LPCWSTR pszSpec,
    DWORD dwFlags
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int PathMatchSpecExW(
    [MarshalAs(UnmanagedType.LPWStr)] string pszFile,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string pszSpec,   // LPCWSTR
    uint dwFlags   // DWORD
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function PathMatchSpecExW(
    <MarshalAs(UnmanagedType.LPWStr)> pszFile As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pszSpec As String,   ' LPCWSTR
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' pszFile : LPCWSTR
' pszSpec : LPCWSTR
' dwFlags : DWORD
Declare PtrSafe Function PathMatchSpecExW Lib "shlwapi" ( _
    ByVal pszFile As LongPtr, _
    ByVal pszSpec As LongPtr, _
    ByVal dwFlags 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

PathMatchSpecExW = ctypes.windll.shlwapi.PathMatchSpecExW
PathMatchSpecExW.restype = ctypes.c_int
PathMatchSpecExW.argtypes = [
    wintypes.LPCWSTR,  # pszFile : LPCWSTR
    wintypes.LPCWSTR,  # pszSpec : LPCWSTR
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
PathMatchSpecExW = Fiddle::Function.new(
  lib['PathMatchSpecExW'],
  [
    Fiddle::TYPE_VOIDP,  # pszFile : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pszSpec : LPCWSTR
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shlwapi")]
extern "system" {
    fn PathMatchSpecExW(
        pszFile: *const u16,  // LPCWSTR
        pszSpec: *const u16,  // LPCWSTR
        dwFlags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern int PathMatchSpecExW([MarshalAs(UnmanagedType.LPWStr)] string pszFile, [MarshalAs(UnmanagedType.LPWStr)] string pszSpec, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathMatchSpecExW' -Namespace Win32 -PassThru
# $api::PathMatchSpecExW(pszFile, pszSpec, dwFlags)
#uselib "SHLWAPI.dll"
#func global PathMatchSpecExW "PathMatchSpecExW" wptr, wptr, wptr
; PathMatchSpecExW pszFile, pszSpec, dwFlags   ; 戻り値は stat
; pszFile : LPCWSTR -> "wptr"
; pszSpec : LPCWSTR -> "wptr"
; dwFlags : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global PathMatchSpecExW "PathMatchSpecExW" wstr, wstr, int
; res = PathMatchSpecExW(pszFile, pszSpec, dwFlags)
; pszFile : LPCWSTR -> "wstr"
; pszSpec : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
; HRESULT PathMatchSpecExW(LPCWSTR pszFile, LPCWSTR pszSpec, DWORD dwFlags)
#uselib "SHLWAPI.dll"
#cfunc global PathMatchSpecExW "PathMatchSpecExW" wstr, wstr, int
; res = PathMatchSpecExW(pszFile, pszSpec, dwFlags)
; pszFile : LPCWSTR -> "wstr"
; pszSpec : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procPathMatchSpecExW = shlwapi.NewProc("PathMatchSpecExW")
)

// pszFile (LPCWSTR), pszSpec (LPCWSTR), dwFlags (DWORD)
r1, _, err := procPathMatchSpecExW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszFile))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSpec))),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function PathMatchSpecExW(
  pszFile: PWideChar;   // LPCWSTR
  pszSpec: PWideChar;   // LPCWSTR
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'PathMatchSpecExW';
result := DllCall("SHLWAPI\PathMatchSpecExW"
    , "WStr", pszFile   ; LPCWSTR
    , "WStr", pszSpec   ; LPCWSTR
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: HRESULT
●PathMatchSpecExW(pszFile, pszSpec, dwFlags) = DLL("SHLWAPI.dll", "int PathMatchSpecExW(char*, char*, dword)")
# 呼び出し: PathMatchSpecExW(pszFile, pszSpec, dwFlags)
# pszFile : LPCWSTR -> "char*"
# pszSpec : LPCWSTR -> "char*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。