SHCreateDirectoryExW
関数中間階層を含むディレクトリ(Unicode)を作成する。
シグネチャ
// SHELL32.dll (Unicode / -W)
#include <windows.h>
INT SHCreateDirectoryExW(
HWND hwnd, // optional
LPCWSTR pszPath,
const SECURITY_ATTRIBUTES* psa // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hwnd | HWND | inoptional |
| pszPath | LPCWSTR | in |
| psa | SECURITY_ATTRIBUTES* | inoptional |
戻り値の型: INT
各言語での呼び出し定義
// SHELL32.dll (Unicode / -W)
#include <windows.h>
INT SHCreateDirectoryExW(
HWND hwnd, // optional
LPCWSTR pszPath,
const SECURITY_ATTRIBUTES* psa // optional
);[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SHCreateDirectoryExW(
IntPtr hwnd, // HWND optional
[MarshalAs(UnmanagedType.LPWStr)] string pszPath, // LPCWSTR
IntPtr psa // SECURITY_ATTRIBUTES* optional
);<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHCreateDirectoryExW(
hwnd As IntPtr, ' HWND optional
<MarshalAs(UnmanagedType.LPWStr)> pszPath As String, ' LPCWSTR
psa As IntPtr ' SECURITY_ATTRIBUTES* optional
) As Integer
End Function' hwnd : HWND optional
' pszPath : LPCWSTR
' psa : SECURITY_ATTRIBUTES* optional
Declare PtrSafe Function SHCreateDirectoryExW Lib "shell32" ( _
ByVal hwnd As LongPtr, _
ByVal pszPath As LongPtr, _
ByVal psa 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
SHCreateDirectoryExW = ctypes.windll.shell32.SHCreateDirectoryExW
SHCreateDirectoryExW.restype = ctypes.c_int
SHCreateDirectoryExW.argtypes = [
wintypes.HANDLE, # hwnd : HWND optional
wintypes.LPCWSTR, # pszPath : LPCWSTR
ctypes.c_void_p, # psa : SECURITY_ATTRIBUTES* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHCreateDirectoryExW = Fiddle::Function.new(
lib['SHCreateDirectoryExW'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND optional
Fiddle::TYPE_VOIDP, # pszPath : LPCWSTR
Fiddle::TYPE_VOIDP, # psa : SECURITY_ATTRIBUTES* optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shell32")]
extern "system" {
fn SHCreateDirectoryExW(
hwnd: *mut core::ffi::c_void, // HWND optional
pszPath: *const u16, // LPCWSTR
psa: *const SECURITY_ATTRIBUTES // SECURITY_ATTRIBUTES* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern int SHCreateDirectoryExW(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszPath, IntPtr psa);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHCreateDirectoryExW' -Namespace Win32 -PassThru
# $api::SHCreateDirectoryExW(hwnd, pszPath, psa)#uselib "SHELL32.dll"
#func global SHCreateDirectoryExW "SHCreateDirectoryExW" wptr, wptr, wptr
; SHCreateDirectoryExW hwnd, pszPath, varptr(psa) ; 戻り値は stat
; hwnd : HWND optional -> "wptr"
; pszPath : LPCWSTR -> "wptr"
; psa : SECURITY_ATTRIBUTES* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global SHCreateDirectoryExW "SHCreateDirectoryExW" sptr, wstr, var ; res = SHCreateDirectoryExW(hwnd, pszPath, psa) ; hwnd : HWND optional -> "sptr" ; pszPath : LPCWSTR -> "wstr" ; psa : SECURITY_ATTRIBUTES* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global SHCreateDirectoryExW "SHCreateDirectoryExW" sptr, wstr, sptr ; res = SHCreateDirectoryExW(hwnd, pszPath, varptr(psa)) ; hwnd : HWND optional -> "sptr" ; pszPath : LPCWSTR -> "wstr" ; psa : SECURITY_ATTRIBUTES* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT SHCreateDirectoryExW(HWND hwnd, LPCWSTR pszPath, SECURITY_ATTRIBUTES* psa) #uselib "SHELL32.dll" #cfunc global SHCreateDirectoryExW "SHCreateDirectoryExW" intptr, wstr, var ; res = SHCreateDirectoryExW(hwnd, pszPath, psa) ; hwnd : HWND optional -> "intptr" ; pszPath : LPCWSTR -> "wstr" ; psa : SECURITY_ATTRIBUTES* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT SHCreateDirectoryExW(HWND hwnd, LPCWSTR pszPath, SECURITY_ATTRIBUTES* psa) #uselib "SHELL32.dll" #cfunc global SHCreateDirectoryExW "SHCreateDirectoryExW" intptr, wstr, intptr ; res = SHCreateDirectoryExW(hwnd, pszPath, varptr(psa)) ; hwnd : HWND optional -> "intptr" ; pszPath : LPCWSTR -> "wstr" ; psa : SECURITY_ATTRIBUTES* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHCreateDirectoryExW = shell32.NewProc("SHCreateDirectoryExW")
)
// hwnd (HWND optional), pszPath (LPCWSTR), psa (SECURITY_ATTRIBUTES* optional)
r1, _, err := procSHCreateDirectoryExW.Call(
uintptr(hwnd),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPath))),
uintptr(psa),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction SHCreateDirectoryExW(
hwnd: THandle; // HWND optional
pszPath: PWideChar; // LPCWSTR
psa: Pointer // SECURITY_ATTRIBUTES* optional
): Integer; stdcall;
external 'SHELL32.dll' name 'SHCreateDirectoryExW';result := DllCall("SHELL32\SHCreateDirectoryExW"
, "Ptr", hwnd ; HWND optional
, "WStr", pszPath ; LPCWSTR
, "Ptr", psa ; SECURITY_ATTRIBUTES* optional
, "Int") ; return: INT●SHCreateDirectoryExW(hwnd, pszPath, psa) = DLL("SHELL32.dll", "int SHCreateDirectoryExW(void*, char*, void*)")
# 呼び出し: SHCreateDirectoryExW(hwnd, pszPath, psa)
# hwnd : HWND optional -> "void*"
# pszPath : LPCWSTR -> "char*"
# psa : SECURITY_ATTRIBUTES* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。