PathIsSameRootW
関数2つのパスが同じルートを共有するかどうかを判定する。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
BOOL PathIsSameRootW(
LPCWSTR pszPath1,
LPCWSTR pszPath2
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszPath1 | LPCWSTR | in |
| pszPath2 | LPCWSTR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
BOOL PathIsSameRootW(
LPCWSTR pszPath1,
LPCWSTR pszPath2
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool PathIsSameRootW(
[MarshalAs(UnmanagedType.LPWStr)] string pszPath1, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pszPath2 // LPCWSTR
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function PathIsSameRootW(
<MarshalAs(UnmanagedType.LPWStr)> pszPath1 As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszPath2 As String ' LPCWSTR
) As Boolean
End Function' pszPath1 : LPCWSTR
' pszPath2 : LPCWSTR
Declare PtrSafe Function PathIsSameRootW Lib "shlwapi" ( _
ByVal pszPath1 As LongPtr, _
ByVal pszPath2 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
PathIsSameRootW = ctypes.windll.shlwapi.PathIsSameRootW
PathIsSameRootW.restype = wintypes.BOOL
PathIsSameRootW.argtypes = [
wintypes.LPCWSTR, # pszPath1 : LPCWSTR
wintypes.LPCWSTR, # pszPath2 : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
PathIsSameRootW = Fiddle::Function.new(
lib['PathIsSameRootW'],
[
Fiddle::TYPE_VOIDP, # pszPath1 : LPCWSTR
Fiddle::TYPE_VOIDP, # pszPath2 : LPCWSTR
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shlwapi")]
extern "system" {
fn PathIsSameRootW(
pszPath1: *const u16, // LPCWSTR
pszPath2: *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 PathIsSameRootW([MarshalAs(UnmanagedType.LPWStr)] string pszPath1, [MarshalAs(UnmanagedType.LPWStr)] string pszPath2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathIsSameRootW' -Namespace Win32 -PassThru
# $api::PathIsSameRootW(pszPath1, pszPath2)#uselib "SHLWAPI.dll"
#func global PathIsSameRootW "PathIsSameRootW" wptr, wptr
; PathIsSameRootW pszPath1, pszPath2 ; 戻り値は stat
; pszPath1 : LPCWSTR -> "wptr"
; pszPath2 : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHLWAPI.dll"
#cfunc global PathIsSameRootW "PathIsSameRootW" wstr, wstr
; res = PathIsSameRootW(pszPath1, pszPath2)
; pszPath1 : LPCWSTR -> "wstr"
; pszPath2 : LPCWSTR -> "wstr"; BOOL PathIsSameRootW(LPCWSTR pszPath1, LPCWSTR pszPath2)
#uselib "SHLWAPI.dll"
#cfunc global PathIsSameRootW "PathIsSameRootW" wstr, wstr
; res = PathIsSameRootW(pszPath1, pszPath2)
; pszPath1 : LPCWSTR -> "wstr"
; pszPath2 : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procPathIsSameRootW = shlwapi.NewProc("PathIsSameRootW")
)
// pszPath1 (LPCWSTR), pszPath2 (LPCWSTR)
r1, _, err := procPathIsSameRootW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPath1))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPath2))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction PathIsSameRootW(
pszPath1: PWideChar; // LPCWSTR
pszPath2: PWideChar // LPCWSTR
): BOOL; stdcall;
external 'SHLWAPI.dll' name 'PathIsSameRootW';result := DllCall("SHLWAPI\PathIsSameRootW"
, "WStr", pszPath1 ; LPCWSTR
, "WStr", pszPath2 ; LPCWSTR
, "Int") ; return: BOOL●PathIsSameRootW(pszPath1, pszPath2) = DLL("SHLWAPI.dll", "bool PathIsSameRootW(char*, char*)")
# 呼び出し: PathIsSameRootW(pszPath1, pszPath2)
# pszPath1 : LPCWSTR -> "char*"
# pszPath2 : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。