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

PathUndecorateW

関数
ファイル名に付いた連番などの装飾を取り除く。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

void PathUndecorateW(
    LPWSTR pszPath
);

パラメーター

名前方向説明
pszPathLPWSTRinoutファイル名に付いた装飾(末尾の[N]など)を除去するパスの入出力バッファ。

戻り値の型: void

各言語での呼び出し定義

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

void PathUndecorateW(
    LPWSTR pszPath
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern void PathUndecorateW(
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath   // LPWSTR in/out
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Sub PathUndecorateW(
    <MarshalAs(UnmanagedType.LPWStr)> pszPath As System.Text.StringBuilder   ' LPWSTR in/out
)
End Sub
' pszPath : LPWSTR in/out
Declare PtrSafe Sub PathUndecorateW Lib "shlwapi" ( _
    ByVal pszPath As LongPtr)
' 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

PathUndecorateW = ctypes.windll.shlwapi.PathUndecorateW
PathUndecorateW.restype = None
PathUndecorateW.argtypes = [
    wintypes.LPWSTR,  # pszPath : LPWSTR in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
PathUndecorateW = Fiddle::Function.new(
  lib['PathUndecorateW'],
  [
    Fiddle::TYPE_VOIDP,  # pszPath : LPWSTR in/out
  ],
  Fiddle::TYPE_VOID)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shlwapi")]
extern "system" {
    fn PathUndecorateW(
        pszPath: *mut u16  // LPWSTR in/out
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern void PathUndecorateW([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathUndecorateW' -Namespace Win32 -PassThru
# $api::PathUndecorateW(pszPath)
#uselib "SHLWAPI.dll"
#func global PathUndecorateW "PathUndecorateW" wptr
; PathUndecorateW varptr(pszPath)
; pszPath : LPWSTR in/out -> "wptr"
出力引数:
#uselib "SHLWAPI.dll"
#func global PathUndecorateW "PathUndecorateW" var
; PathUndecorateW pszPath
; pszPath : LPWSTR in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void PathUndecorateW(LPWSTR pszPath)
#uselib "SHLWAPI.dll"
#func global PathUndecorateW "PathUndecorateW" var
; PathUndecorateW pszPath
; pszPath : LPWSTR in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procPathUndecorateW = shlwapi.NewProc("PathUndecorateW")
)

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