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