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

PathCleanupSpec

関数
ファイル名から無効な文字を除去し有効な名前に整える。
DLLSHELL32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// SHELL32.dll
#include <windows.h>

INT PathCleanupSpec(
    LPCWSTR pszDir,   // optional
    LPWSTR pszSpec
);

パラメーター

名前方向
pszDirLPCWSTRinoptional
pszSpecLPWSTRinout

戻り値の型: INT

各言語での呼び出し定義

// SHELL32.dll
#include <windows.h>

INT PathCleanupSpec(
    LPCWSTR pszDir,   // optional
    LPWSTR pszSpec
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int PathCleanupSpec(
    [MarshalAs(UnmanagedType.LPWStr)] string pszDir,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszSpec   // LPWSTR in/out
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function PathCleanupSpec(
    <MarshalAs(UnmanagedType.LPWStr)> pszDir As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> pszSpec As System.Text.StringBuilder   ' LPWSTR in/out
) As Integer
End Function
' pszDir : LPCWSTR optional
' pszSpec : LPWSTR in/out
Declare PtrSafe Function PathCleanupSpec Lib "shell32" ( _
    ByVal pszDir As LongPtr, _
    ByVal pszSpec As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PathCleanupSpec = ctypes.windll.shell32.PathCleanupSpec
PathCleanupSpec.restype = ctypes.c_int
PathCleanupSpec.argtypes = [
    wintypes.LPCWSTR,  # pszDir : LPCWSTR optional
    wintypes.LPWSTR,  # pszSpec : LPWSTR in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
PathCleanupSpec = Fiddle::Function.new(
  lib['PathCleanupSpec'],
  [
    Fiddle::TYPE_VOIDP,  # pszDir : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pszSpec : LPWSTR in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "shell32")]
extern "system" {
    fn PathCleanupSpec(
        pszDir: *const u16,  // LPCWSTR optional
        pszSpec: *mut u16  // LPWSTR in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll")]
public static extern int PathCleanupSpec([MarshalAs(UnmanagedType.LPWStr)] string pszDir, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszSpec);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_PathCleanupSpec' -Namespace Win32 -PassThru
# $api::PathCleanupSpec(pszDir, pszSpec)
#uselib "SHELL32.dll"
#func global PathCleanupSpec "PathCleanupSpec" sptr, sptr
; PathCleanupSpec pszDir, varptr(pszSpec)   ; 戻り値は stat
; pszDir : LPCWSTR optional -> "sptr"
; pszSpec : LPWSTR in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHELL32.dll"
#cfunc global PathCleanupSpec "PathCleanupSpec" wstr, var
; res = PathCleanupSpec(pszDir, pszSpec)
; pszDir : LPCWSTR optional -> "wstr"
; pszSpec : LPWSTR in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT PathCleanupSpec(LPCWSTR pszDir, LPWSTR pszSpec)
#uselib "SHELL32.dll"
#cfunc global PathCleanupSpec "PathCleanupSpec" wstr, var
; res = PathCleanupSpec(pszDir, pszSpec)
; pszDir : LPCWSTR optional -> "wstr"
; pszSpec : LPWSTR in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procPathCleanupSpec = shell32.NewProc("PathCleanupSpec")
)

// pszDir (LPCWSTR optional), pszSpec (LPWSTR in/out)
r1, _, err := procPathCleanupSpec.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszDir))),
	uintptr(pszSpec),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function PathCleanupSpec(
  pszDir: PWideChar;   // LPCWSTR optional
  pszSpec: PWideChar   // LPWSTR in/out
): Integer; stdcall;
  external 'SHELL32.dll' name 'PathCleanupSpec';
result := DllCall("SHELL32\PathCleanupSpec"
    , "WStr", pszDir   ; LPCWSTR optional
    , "Ptr", pszSpec   ; LPWSTR in/out
    , "Int")   ; return: INT
●PathCleanupSpec(pszDir, pszSpec) = DLL("SHELL32.dll", "int PathCleanupSpec(char*, char*)")
# 呼び出し: PathCleanupSpec(pszDir, pszSpec)
# pszDir : LPCWSTR optional -> "char*"
# pszSpec : LPWSTR in/out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。