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

PathIsPrefixW

関数
指定のプレフィックスがパスの先頭に含まれるか判定する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL PathIsPrefixW(
    LPCWSTR pszPrefix,
    LPCWSTR pszPath
);

パラメーター

名前方向
pszPrefixLPCWSTRin
pszPathLPCWSTRin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

PathIsPrefixW = ctypes.windll.shlwapi.PathIsPrefixW
PathIsPrefixW.restype = wintypes.BOOL
PathIsPrefixW.argtypes = [
    wintypes.LPCWSTR,  # pszPrefix : LPCWSTR
    wintypes.LPCWSTR,  # pszPath : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
PathIsPrefixW = Fiddle::Function.new(
  lib['PathIsPrefixW'],
  [
    Fiddle::TYPE_VOIDP,  # pszPrefix : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pszPath : LPCWSTR
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shlwapi")]
extern "system" {
    fn PathIsPrefixW(
        pszPrefix: *const u16,  // LPCWSTR
        pszPath: *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 PathIsPrefixW([MarshalAs(UnmanagedType.LPWStr)] string pszPrefix, [MarshalAs(UnmanagedType.LPWStr)] string pszPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathIsPrefixW' -Namespace Win32 -PassThru
# $api::PathIsPrefixW(pszPrefix, pszPath)
#uselib "SHLWAPI.dll"
#func global PathIsPrefixW "PathIsPrefixW" wptr, wptr
; PathIsPrefixW pszPrefix, pszPath   ; 戻り値は stat
; pszPrefix : LPCWSTR -> "wptr"
; pszPath : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global PathIsPrefixW "PathIsPrefixW" wstr, wstr
; res = PathIsPrefixW(pszPrefix, pszPath)
; pszPrefix : LPCWSTR -> "wstr"
; pszPath : LPCWSTR -> "wstr"
; BOOL PathIsPrefixW(LPCWSTR pszPrefix, LPCWSTR pszPath)
#uselib "SHLWAPI.dll"
#cfunc global PathIsPrefixW "PathIsPrefixW" wstr, wstr
; res = PathIsPrefixW(pszPrefix, pszPath)
; pszPrefix : LPCWSTR -> "wstr"
; pszPath : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procPathIsPrefixW = shlwapi.NewProc("PathIsPrefixW")
)

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