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