PathCompactPathExW
関数指定の文字数に収まるよう、パスを省略記号付きで短縮する。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
BOOL PathCompactPathExW(
LPWSTR pszOut,
LPCWSTR pszSrc,
DWORD cchMax,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszOut | LPWSTR | out |
| pszSrc | LPCWSTR | in |
| cchMax | DWORD | in |
| dwFlags | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
BOOL PathCompactPathExW(
LPWSTR pszOut,
LPCWSTR pszSrc,
DWORD cchMax,
DWORD dwFlags
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool PathCompactPathExW(
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszOut, // LPWSTR out
[MarshalAs(UnmanagedType.LPWStr)] string pszSrc, // LPCWSTR
uint cchMax, // DWORD
uint dwFlags // DWORD
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function PathCompactPathExW(
<MarshalAs(UnmanagedType.LPWStr)> pszOut As System.Text.StringBuilder, ' LPWSTR out
<MarshalAs(UnmanagedType.LPWStr)> pszSrc As String, ' LPCWSTR
cchMax As UInteger, ' DWORD
dwFlags As UInteger ' DWORD
) As Boolean
End Function' pszOut : LPWSTR out
' pszSrc : LPCWSTR
' cchMax : DWORD
' dwFlags : DWORD
Declare PtrSafe Function PathCompactPathExW Lib "shlwapi" ( _
ByVal pszOut As LongPtr, _
ByVal pszSrc As LongPtr, _
ByVal cchMax As Long, _
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
PathCompactPathExW = ctypes.windll.shlwapi.PathCompactPathExW
PathCompactPathExW.restype = wintypes.BOOL
PathCompactPathExW.argtypes = [
wintypes.LPWSTR, # pszOut : LPWSTR out
wintypes.LPCWSTR, # pszSrc : LPCWSTR
wintypes.DWORD, # cchMax : DWORD
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
PathCompactPathExW = Fiddle::Function.new(
lib['PathCompactPathExW'],
[
Fiddle::TYPE_VOIDP, # pszOut : LPWSTR out
Fiddle::TYPE_VOIDP, # pszSrc : LPCWSTR
-Fiddle::TYPE_INT, # cchMax : DWORD
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shlwapi")]
extern "system" {
fn PathCompactPathExW(
pszOut: *mut u16, // LPWSTR out
pszSrc: *const u16, // LPCWSTR
cchMax: u32, // DWORD
dwFlags: u32 // DWORD
) -> 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 PathCompactPathExW([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszOut, [MarshalAs(UnmanagedType.LPWStr)] string pszSrc, uint cchMax, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathCompactPathExW' -Namespace Win32 -PassThru
# $api::PathCompactPathExW(pszOut, pszSrc, cchMax, dwFlags)#uselib "SHLWAPI.dll"
#func global PathCompactPathExW "PathCompactPathExW" wptr, wptr, wptr, wptr
; PathCompactPathExW varptr(pszOut), pszSrc, cchMax, dwFlags ; 戻り値は stat
; pszOut : LPWSTR out -> "wptr"
; pszSrc : LPCWSTR -> "wptr"
; cchMax : DWORD -> "wptr"
; dwFlags : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global PathCompactPathExW "PathCompactPathExW" var, wstr, int, int ; res = PathCompactPathExW(pszOut, pszSrc, cchMax, dwFlags) ; pszOut : LPWSTR out -> "var" ; pszSrc : LPCWSTR -> "wstr" ; cchMax : DWORD -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global PathCompactPathExW "PathCompactPathExW" sptr, wstr, int, int ; res = PathCompactPathExW(varptr(pszOut), pszSrc, cchMax, dwFlags) ; pszOut : LPWSTR out -> "sptr" ; pszSrc : LPCWSTR -> "wstr" ; cchMax : DWORD -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL PathCompactPathExW(LPWSTR pszOut, LPCWSTR pszSrc, DWORD cchMax, DWORD dwFlags) #uselib "SHLWAPI.dll" #cfunc global PathCompactPathExW "PathCompactPathExW" var, wstr, int, int ; res = PathCompactPathExW(pszOut, pszSrc, cchMax, dwFlags) ; pszOut : LPWSTR out -> "var" ; pszSrc : LPCWSTR -> "wstr" ; cchMax : DWORD -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL PathCompactPathExW(LPWSTR pszOut, LPCWSTR pszSrc, DWORD cchMax, DWORD dwFlags) #uselib "SHLWAPI.dll" #cfunc global PathCompactPathExW "PathCompactPathExW" intptr, wstr, int, int ; res = PathCompactPathExW(varptr(pszOut), pszSrc, cchMax, dwFlags) ; pszOut : LPWSTR out -> "intptr" ; pszSrc : LPCWSTR -> "wstr" ; cchMax : DWORD -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procPathCompactPathExW = shlwapi.NewProc("PathCompactPathExW")
)
// pszOut (LPWSTR out), pszSrc (LPCWSTR), cchMax (DWORD), dwFlags (DWORD)
r1, _, err := procPathCompactPathExW.Call(
uintptr(pszOut),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSrc))),
uintptr(cchMax),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction PathCompactPathExW(
pszOut: PWideChar; // LPWSTR out
pszSrc: PWideChar; // LPCWSTR
cchMax: DWORD; // DWORD
dwFlags: DWORD // DWORD
): BOOL; stdcall;
external 'SHLWAPI.dll' name 'PathCompactPathExW';result := DllCall("SHLWAPI\PathCompactPathExW"
, "Ptr", pszOut ; LPWSTR out
, "WStr", pszSrc ; LPCWSTR
, "UInt", cchMax ; DWORD
, "UInt", dwFlags ; DWORD
, "Int") ; return: BOOL●PathCompactPathExW(pszOut, pszSrc, cchMax, dwFlags) = DLL("SHLWAPI.dll", "bool PathCompactPathExW(char*, char*, dword, dword)")
# 呼び出し: PathCompactPathExW(pszOut, pszSrc, cchMax, dwFlags)
# pszOut : LPWSTR out -> "char*"
# pszSrc : LPCWSTR -> "char*"
# cchMax : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。