PathYetAnotherMakeUniqueName
関数指定ディレクトリ内で重複しない一意のファイル名を生成する。
シグネチャ
// SHELL32.dll
#include <windows.h>
BOOL PathYetAnotherMakeUniqueName(
LPWSTR pszUniqueName,
LPCWSTR pszPath,
LPCWSTR pszShort, // optional
LPCWSTR pszFileSpec // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszUniqueName | LPWSTR | out |
| pszPath | LPCWSTR | in |
| pszShort | LPCWSTR | inoptional |
| pszFileSpec | LPCWSTR | inoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// SHELL32.dll
#include <windows.h>
BOOL PathYetAnotherMakeUniqueName(
LPWSTR pszUniqueName,
LPCWSTR pszPath,
LPCWSTR pszShort, // optional
LPCWSTR pszFileSpec // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern bool PathYetAnotherMakeUniqueName(
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszUniqueName, // LPWSTR out
[MarshalAs(UnmanagedType.LPWStr)] string pszPath, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pszShort, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pszFileSpec // LPCWSTR optional
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function PathYetAnotherMakeUniqueName(
<MarshalAs(UnmanagedType.LPWStr)> pszUniqueName As System.Text.StringBuilder, ' LPWSTR out
<MarshalAs(UnmanagedType.LPWStr)> pszPath As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszShort As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pszFileSpec As String ' LPCWSTR optional
) As Boolean
End Function' pszUniqueName : LPWSTR out
' pszPath : LPCWSTR
' pszShort : LPCWSTR optional
' pszFileSpec : LPCWSTR optional
Declare PtrSafe Function PathYetAnotherMakeUniqueName Lib "shell32" ( _
ByVal pszUniqueName As LongPtr, _
ByVal pszPath As LongPtr, _
ByVal pszShort As LongPtr, _
ByVal pszFileSpec As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PathYetAnotherMakeUniqueName = ctypes.windll.shell32.PathYetAnotherMakeUniqueName
PathYetAnotherMakeUniqueName.restype = wintypes.BOOL
PathYetAnotherMakeUniqueName.argtypes = [
wintypes.LPWSTR, # pszUniqueName : LPWSTR out
wintypes.LPCWSTR, # pszPath : LPCWSTR
wintypes.LPCWSTR, # pszShort : LPCWSTR optional
wintypes.LPCWSTR, # pszFileSpec : LPCWSTR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
PathYetAnotherMakeUniqueName = Fiddle::Function.new(
lib['PathYetAnotherMakeUniqueName'],
[
Fiddle::TYPE_VOIDP, # pszUniqueName : LPWSTR out
Fiddle::TYPE_VOIDP, # pszPath : LPCWSTR
Fiddle::TYPE_VOIDP, # pszShort : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pszFileSpec : LPCWSTR optional
],
Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn PathYetAnotherMakeUniqueName(
pszUniqueName: *mut u16, // LPWSTR out
pszPath: *const u16, // LPCWSTR
pszShort: *const u16, // LPCWSTR optional
pszFileSpec: *const u16 // LPCWSTR optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHELL32.dll")]
public static extern bool PathYetAnotherMakeUniqueName([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszUniqueName, [MarshalAs(UnmanagedType.LPWStr)] string pszPath, [MarshalAs(UnmanagedType.LPWStr)] string pszShort, [MarshalAs(UnmanagedType.LPWStr)] string pszFileSpec);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_PathYetAnotherMakeUniqueName' -Namespace Win32 -PassThru
# $api::PathYetAnotherMakeUniqueName(pszUniqueName, pszPath, pszShort, pszFileSpec)#uselib "SHELL32.dll"
#func global PathYetAnotherMakeUniqueName "PathYetAnotherMakeUniqueName" sptr, sptr, sptr, sptr
; PathYetAnotherMakeUniqueName varptr(pszUniqueName), pszPath, pszShort, pszFileSpec ; 戻り値は stat
; pszUniqueName : LPWSTR out -> "sptr"
; pszPath : LPCWSTR -> "sptr"
; pszShort : LPCWSTR optional -> "sptr"
; pszFileSpec : LPCWSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global PathYetAnotherMakeUniqueName "PathYetAnotherMakeUniqueName" var, wstr, wstr, wstr ; res = PathYetAnotherMakeUniqueName(pszUniqueName, pszPath, pszShort, pszFileSpec) ; pszUniqueName : LPWSTR out -> "var" ; pszPath : LPCWSTR -> "wstr" ; pszShort : LPCWSTR optional -> "wstr" ; pszFileSpec : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global PathYetAnotherMakeUniqueName "PathYetAnotherMakeUniqueName" sptr, wstr, wstr, wstr ; res = PathYetAnotherMakeUniqueName(varptr(pszUniqueName), pszPath, pszShort, pszFileSpec) ; pszUniqueName : LPWSTR out -> "sptr" ; pszPath : LPCWSTR -> "wstr" ; pszShort : LPCWSTR optional -> "wstr" ; pszFileSpec : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL PathYetAnotherMakeUniqueName(LPWSTR pszUniqueName, LPCWSTR pszPath, LPCWSTR pszShort, LPCWSTR pszFileSpec) #uselib "SHELL32.dll" #cfunc global PathYetAnotherMakeUniqueName "PathYetAnotherMakeUniqueName" var, wstr, wstr, wstr ; res = PathYetAnotherMakeUniqueName(pszUniqueName, pszPath, pszShort, pszFileSpec) ; pszUniqueName : LPWSTR out -> "var" ; pszPath : LPCWSTR -> "wstr" ; pszShort : LPCWSTR optional -> "wstr" ; pszFileSpec : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL PathYetAnotherMakeUniqueName(LPWSTR pszUniqueName, LPCWSTR pszPath, LPCWSTR pszShort, LPCWSTR pszFileSpec) #uselib "SHELL32.dll" #cfunc global PathYetAnotherMakeUniqueName "PathYetAnotherMakeUniqueName" intptr, wstr, wstr, wstr ; res = PathYetAnotherMakeUniqueName(varptr(pszUniqueName), pszPath, pszShort, pszFileSpec) ; pszUniqueName : LPWSTR out -> "intptr" ; pszPath : LPCWSTR -> "wstr" ; pszShort : LPCWSTR optional -> "wstr" ; pszFileSpec : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procPathYetAnotherMakeUniqueName = shell32.NewProc("PathYetAnotherMakeUniqueName")
)
// pszUniqueName (LPWSTR out), pszPath (LPCWSTR), pszShort (LPCWSTR optional), pszFileSpec (LPCWSTR optional)
r1, _, err := procPathYetAnotherMakeUniqueName.Call(
uintptr(pszUniqueName),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPath))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszShort))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszFileSpec))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction PathYetAnotherMakeUniqueName(
pszUniqueName: PWideChar; // LPWSTR out
pszPath: PWideChar; // LPCWSTR
pszShort: PWideChar; // LPCWSTR optional
pszFileSpec: PWideChar // LPCWSTR optional
): BOOL; stdcall;
external 'SHELL32.dll' name 'PathYetAnotherMakeUniqueName';result := DllCall("SHELL32\PathYetAnotherMakeUniqueName"
, "Ptr", pszUniqueName ; LPWSTR out
, "WStr", pszPath ; LPCWSTR
, "WStr", pszShort ; LPCWSTR optional
, "WStr", pszFileSpec ; LPCWSTR optional
, "Int") ; return: BOOL●PathYetAnotherMakeUniqueName(pszUniqueName, pszPath, pszShort, pszFileSpec) = DLL("SHELL32.dll", "bool PathYetAnotherMakeUniqueName(char*, char*, char*, char*)")
# 呼び出し: PathYetAnotherMakeUniqueName(pszUniqueName, pszPath, pszShort, pszFileSpec)
# pszUniqueName : LPWSTR out -> "char*"
# pszPath : LPCWSTR -> "char*"
# pszShort : LPCWSTR optional -> "char*"
# pszFileSpec : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。