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