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

SHPathPrepareForWriteA

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

シグネチャ

// SHELL32.dll  (ANSI / -A)
#include <windows.h>

HRESULT SHPathPrepareForWriteA(
    HWND hwnd,   // optional
    IUnknown* punkEnableModless,   // optional
    LPCSTR pszPath,
    DWORD dwFlags
);

パラメーター

名前方向
hwndHWNDinoptional
punkEnableModlessIUnknown*inoptional
pszPathLPCSTRin
dwFlagsDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

// SHELL32.dll  (ANSI / -A)
#include <windows.h>

HRESULT SHPathPrepareForWriteA(
    HWND hwnd,   // optional
    IUnknown* punkEnableModless,   // optional
    LPCSTR pszPath,
    DWORD dwFlags
);
[DllImport("SHELL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int SHPathPrepareForWriteA(
    IntPtr hwnd,   // HWND optional
    IntPtr punkEnableModless,   // IUnknown* optional
    [MarshalAs(UnmanagedType.LPStr)] string pszPath,   // LPCSTR
    uint dwFlags   // DWORD
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SHPathPrepareForWriteA(
    hwnd As IntPtr,   ' HWND optional
    punkEnableModless As IntPtr,   ' IUnknown* optional
    <MarshalAs(UnmanagedType.LPStr)> pszPath As String,   ' LPCSTR
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' hwnd : HWND optional
' punkEnableModless : IUnknown* optional
' pszPath : LPCSTR
' dwFlags : DWORD
Declare PtrSafe Function SHPathPrepareForWriteA Lib "shell32" ( _
    ByVal hwnd As LongPtr, _
    ByVal punkEnableModless As LongPtr, _
    ByVal pszPath As String, _
    ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHPathPrepareForWriteA = shell32.NewProc("SHPathPrepareForWriteA")
)

// hwnd (HWND optional), punkEnableModless (IUnknown* optional), pszPath (LPCSTR), dwFlags (DWORD)
r1, _, err := procSHPathPrepareForWriteA.Call(
	uintptr(hwnd),
	uintptr(punkEnableModless),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszPath))),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SHPathPrepareForWriteA(
  hwnd: THandle;   // HWND optional
  punkEnableModless: Pointer;   // IUnknown* optional
  pszPath: PAnsiChar;   // LPCSTR
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'SHELL32.dll' name 'SHPathPrepareForWriteA';
result := DllCall("SHELL32\SHPathPrepareForWriteA"
    , "Ptr", hwnd   ; HWND optional
    , "Ptr", punkEnableModless   ; IUnknown* optional
    , "AStr", pszPath   ; LPCSTR
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: HRESULT
●SHPathPrepareForWriteA(hwnd, punkEnableModless, pszPath, dwFlags) = DLL("SHELL32.dll", "int SHPathPrepareForWriteA(void*, void*, char*, dword)")
# 呼び出し: SHPathPrepareForWriteA(hwnd, punkEnableModless, pszPath, dwFlags)
# hwnd : HWND optional -> "void*"
# punkEnableModless : IUnknown* optional -> "void*"
# pszPath : LPCSTR -> "char*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。