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