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

SHPathPrepareForWriteW

関数
書き込みに備えパス(Unicode)の媒体やフォルダーを準備する。
DLLSHELL32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT SHPathPrepareForWriteW(
    HWND hwnd,   // optional
    IUnknown* punkEnableModless,   // optional
    LPCWSTR pszPath,
    DWORD dwFlags
);

パラメーター

名前方向
hwndHWNDinoptional
punkEnableModlessIUnknown*inoptional
pszPathLPCWSTRin
dwFlagsDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SHPathPrepareForWriteW(
    HWND hwnd,   // optional
    IUnknown* punkEnableModless,   // optional
    LPCWSTR pszPath,
    DWORD dwFlags
);
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SHPathPrepareForWriteW(
    IntPtr hwnd,   // HWND optional
    IntPtr punkEnableModless,   // IUnknown* optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszPath,   // LPCWSTR
    uint dwFlags   // DWORD
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHPathPrepareForWriteW(
    hwnd As IntPtr,   ' HWND optional
    punkEnableModless As IntPtr,   ' IUnknown* optional
    <MarshalAs(UnmanagedType.LPWStr)> pszPath As String,   ' LPCWSTR
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' hwnd : HWND optional
' punkEnableModless : IUnknown* optional
' pszPath : LPCWSTR
' dwFlags : DWORD
Declare PtrSafe Function SHPathPrepareForWriteW Lib "shell32" ( _
    ByVal hwnd As LongPtr, _
    ByVal punkEnableModless As LongPtr, _
    ByVal pszPath As LongPtr, _
    ByVal dwFlags As Long) 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

SHPathPrepareForWriteW = ctypes.windll.shell32.SHPathPrepareForWriteW
SHPathPrepareForWriteW.restype = ctypes.c_int
SHPathPrepareForWriteW.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND optional
    ctypes.c_void_p,  # punkEnableModless : IUnknown* optional
    wintypes.LPCWSTR,  # pszPath : LPCWSTR
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
SHPathPrepareForWriteW = Fiddle::Function.new(
  lib['SHPathPrepareForWriteW'],
  [
    Fiddle::TYPE_VOIDP,  # hwnd : HWND optional
    Fiddle::TYPE_VOIDP,  # punkEnableModless : IUnknown* optional
    Fiddle::TYPE_VOIDP,  # pszPath : LPCWSTR
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shell32")]
extern "system" {
    fn SHPathPrepareForWriteW(
        hwnd: *mut core::ffi::c_void,  // HWND optional
        punkEnableModless: *mut core::ffi::c_void,  // IUnknown* optional
        pszPath: *const u16,  // LPCWSTR
        dwFlags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern int SHPathPrepareForWriteW(IntPtr hwnd, IntPtr punkEnableModless, [MarshalAs(UnmanagedType.LPWStr)] string pszPath, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHPathPrepareForWriteW' -Namespace Win32 -PassThru
# $api::SHPathPrepareForWriteW(hwnd, punkEnableModless, pszPath, dwFlags)
#uselib "SHELL32.dll"
#func global SHPathPrepareForWriteW "SHPathPrepareForWriteW" wptr, wptr, wptr, wptr
; SHPathPrepareForWriteW hwnd, punkEnableModless, pszPath, dwFlags   ; 戻り値は stat
; hwnd : HWND optional -> "wptr"
; punkEnableModless : IUnknown* optional -> "wptr"
; pszPath : LPCWSTR -> "wptr"
; dwFlags : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHELL32.dll"
#cfunc global SHPathPrepareForWriteW "SHPathPrepareForWriteW" sptr, sptr, wstr, int
; res = SHPathPrepareForWriteW(hwnd, punkEnableModless, pszPath, dwFlags)
; hwnd : HWND optional -> "sptr"
; punkEnableModless : IUnknown* optional -> "sptr"
; pszPath : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
; HRESULT SHPathPrepareForWriteW(HWND hwnd, IUnknown* punkEnableModless, LPCWSTR pszPath, DWORD dwFlags)
#uselib "SHELL32.dll"
#cfunc global SHPathPrepareForWriteW "SHPathPrepareForWriteW" intptr, intptr, wstr, int
; res = SHPathPrepareForWriteW(hwnd, punkEnableModless, pszPath, dwFlags)
; hwnd : HWND optional -> "intptr"
; punkEnableModless : IUnknown* optional -> "intptr"
; pszPath : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHPathPrepareForWriteW = shell32.NewProc("SHPathPrepareForWriteW")
)

// hwnd (HWND optional), punkEnableModless (IUnknown* optional), pszPath (LPCWSTR), dwFlags (DWORD)
r1, _, err := procSHPathPrepareForWriteW.Call(
	uintptr(hwnd),
	uintptr(punkEnableModless),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPath))),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SHPathPrepareForWriteW(
  hwnd: THandle;   // HWND optional
  punkEnableModless: Pointer;   // IUnknown* optional
  pszPath: PWideChar;   // LPCWSTR
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'SHELL32.dll' name 'SHPathPrepareForWriteW';
result := DllCall("SHELL32\SHPathPrepareForWriteW"
    , "Ptr", hwnd   ; HWND optional
    , "Ptr", punkEnableModless   ; IUnknown* optional
    , "WStr", pszPath   ; LPCWSTR
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: HRESULT
●SHPathPrepareForWriteW(hwnd, punkEnableModless, pszPath, dwFlags) = DLL("SHELL32.dll", "int SHPathPrepareForWriteW(void*, void*, char*, dword)")
# 呼び出し: SHPathPrepareForWriteW(hwnd, punkEnableModless, pszPath, dwFlags)
# hwnd : HWND optional -> "void*"
# punkEnableModless : IUnknown* optional -> "void*"
# pszPath : LPCWSTR -> "char*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。