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

PathMatchSpecW

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

シグネチャ

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

BOOL PathMatchSpecW(
    LPCWSTR pszFile,
    LPCWSTR pszSpec
);

パラメーター

名前方向
pszFileLPCWSTRin
pszSpecLPCWSTRin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL PathMatchSpecW(
    LPCWSTR pszFile,
    LPCWSTR pszSpec
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool PathMatchSpecW(
    [MarshalAs(UnmanagedType.LPWStr)] string pszFile,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string pszSpec   // LPCWSTR
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function PathMatchSpecW(
    <MarshalAs(UnmanagedType.LPWStr)> pszFile As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pszSpec As String   ' LPCWSTR
) As Boolean
End Function
' pszFile : LPCWSTR
' pszSpec : LPCWSTR
Declare PtrSafe Function PathMatchSpecW Lib "shlwapi" ( _
    ByVal pszFile As LongPtr, _
    ByVal pszSpec As LongPtr) 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

PathMatchSpecW = ctypes.windll.shlwapi.PathMatchSpecW
PathMatchSpecW.restype = wintypes.BOOL
PathMatchSpecW.argtypes = [
    wintypes.LPCWSTR,  # pszFile : LPCWSTR
    wintypes.LPCWSTR,  # pszSpec : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procPathMatchSpecW = shlwapi.NewProc("PathMatchSpecW")
)

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