GetFileNameFromBrowse
関数参照ダイアログでファイル名をユーザーに選択させる。
シグネチャ
// SHELL32.dll
#include <windows.h>
BOOL GetFileNameFromBrowse(
HWND hwnd, // optional
LPWSTR pszFilePath,
DWORD cchFilePath,
LPCWSTR pszWorkingDir, // optional
LPCWSTR pszDefExt,
LPCWSTR pszFilters, // optional
LPCWSTR pszTitle // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hwnd | HWND | inoptional |
| pszFilePath | LPWSTR | inout |
| cchFilePath | DWORD | in |
| pszWorkingDir | LPCWSTR | inoptional |
| pszDefExt | LPCWSTR | in |
| pszFilters | LPCWSTR | inoptional |
| pszTitle | LPCWSTR | inoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// SHELL32.dll
#include <windows.h>
BOOL GetFileNameFromBrowse(
HWND hwnd, // optional
LPWSTR pszFilePath,
DWORD cchFilePath,
LPCWSTR pszWorkingDir, // optional
LPCWSTR pszDefExt,
LPCWSTR pszFilters, // optional
LPCWSTR pszTitle // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern bool GetFileNameFromBrowse(
IntPtr hwnd, // HWND optional
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszFilePath, // LPWSTR in/out
uint cchFilePath, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string pszWorkingDir, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pszDefExt, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pszFilters, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pszTitle // LPCWSTR optional
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function GetFileNameFromBrowse(
hwnd As IntPtr, ' HWND optional
<MarshalAs(UnmanagedType.LPWStr)> pszFilePath As System.Text.StringBuilder, ' LPWSTR in/out
cchFilePath As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pszWorkingDir As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pszDefExt As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszFilters As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pszTitle As String ' LPCWSTR optional
) As Boolean
End Function' hwnd : HWND optional
' pszFilePath : LPWSTR in/out
' cchFilePath : DWORD
' pszWorkingDir : LPCWSTR optional
' pszDefExt : LPCWSTR
' pszFilters : LPCWSTR optional
' pszTitle : LPCWSTR optional
Declare PtrSafe Function GetFileNameFromBrowse Lib "shell32" ( _
ByVal hwnd As LongPtr, _
ByVal pszFilePath As LongPtr, _
ByVal cchFilePath As Long, _
ByVal pszWorkingDir As LongPtr, _
ByVal pszDefExt As LongPtr, _
ByVal pszFilters As LongPtr, _
ByVal pszTitle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetFileNameFromBrowse = ctypes.windll.shell32.GetFileNameFromBrowse
GetFileNameFromBrowse.restype = wintypes.BOOL
GetFileNameFromBrowse.argtypes = [
wintypes.HANDLE, # hwnd : HWND optional
wintypes.LPWSTR, # pszFilePath : LPWSTR in/out
wintypes.DWORD, # cchFilePath : DWORD
wintypes.LPCWSTR, # pszWorkingDir : LPCWSTR optional
wintypes.LPCWSTR, # pszDefExt : LPCWSTR
wintypes.LPCWSTR, # pszFilters : LPCWSTR optional
wintypes.LPCWSTR, # pszTitle : LPCWSTR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
GetFileNameFromBrowse = Fiddle::Function.new(
lib['GetFileNameFromBrowse'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND optional
Fiddle::TYPE_VOIDP, # pszFilePath : LPWSTR in/out
-Fiddle::TYPE_INT, # cchFilePath : DWORD
Fiddle::TYPE_VOIDP, # pszWorkingDir : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pszDefExt : LPCWSTR
Fiddle::TYPE_VOIDP, # pszFilters : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pszTitle : LPCWSTR optional
],
Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn GetFileNameFromBrowse(
hwnd: *mut core::ffi::c_void, // HWND optional
pszFilePath: *mut u16, // LPWSTR in/out
cchFilePath: u32, // DWORD
pszWorkingDir: *const u16, // LPCWSTR optional
pszDefExt: *const u16, // LPCWSTR
pszFilters: *const u16, // LPCWSTR optional
pszTitle: *const u16 // LPCWSTR optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHELL32.dll")]
public static extern bool GetFileNameFromBrowse(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszFilePath, uint cchFilePath, [MarshalAs(UnmanagedType.LPWStr)] string pszWorkingDir, [MarshalAs(UnmanagedType.LPWStr)] string pszDefExt, [MarshalAs(UnmanagedType.LPWStr)] string pszFilters, [MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_GetFileNameFromBrowse' -Namespace Win32 -PassThru
# $api::GetFileNameFromBrowse(hwnd, pszFilePath, cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle)#uselib "SHELL32.dll"
#func global GetFileNameFromBrowse "GetFileNameFromBrowse" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GetFileNameFromBrowse hwnd, varptr(pszFilePath), cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle ; 戻り値は stat
; hwnd : HWND optional -> "sptr"
; pszFilePath : LPWSTR in/out -> "sptr"
; cchFilePath : DWORD -> "sptr"
; pszWorkingDir : LPCWSTR optional -> "sptr"
; pszDefExt : LPCWSTR -> "sptr"
; pszFilters : LPCWSTR optional -> "sptr"
; pszTitle : LPCWSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global GetFileNameFromBrowse "GetFileNameFromBrowse" sptr, var, int, wstr, wstr, wstr, wstr ; res = GetFileNameFromBrowse(hwnd, pszFilePath, cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle) ; hwnd : HWND optional -> "sptr" ; pszFilePath : LPWSTR in/out -> "var" ; cchFilePath : DWORD -> "int" ; pszWorkingDir : LPCWSTR optional -> "wstr" ; pszDefExt : LPCWSTR -> "wstr" ; pszFilters : LPCWSTR optional -> "wstr" ; pszTitle : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global GetFileNameFromBrowse "GetFileNameFromBrowse" sptr, sptr, int, wstr, wstr, wstr, wstr ; res = GetFileNameFromBrowse(hwnd, varptr(pszFilePath), cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle) ; hwnd : HWND optional -> "sptr" ; pszFilePath : LPWSTR in/out -> "sptr" ; cchFilePath : DWORD -> "int" ; pszWorkingDir : LPCWSTR optional -> "wstr" ; pszDefExt : LPCWSTR -> "wstr" ; pszFilters : LPCWSTR optional -> "wstr" ; pszTitle : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetFileNameFromBrowse(HWND hwnd, LPWSTR pszFilePath, DWORD cchFilePath, LPCWSTR pszWorkingDir, LPCWSTR pszDefExt, LPCWSTR pszFilters, LPCWSTR pszTitle) #uselib "SHELL32.dll" #cfunc global GetFileNameFromBrowse "GetFileNameFromBrowse" intptr, var, int, wstr, wstr, wstr, wstr ; res = GetFileNameFromBrowse(hwnd, pszFilePath, cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle) ; hwnd : HWND optional -> "intptr" ; pszFilePath : LPWSTR in/out -> "var" ; cchFilePath : DWORD -> "int" ; pszWorkingDir : LPCWSTR optional -> "wstr" ; pszDefExt : LPCWSTR -> "wstr" ; pszFilters : LPCWSTR optional -> "wstr" ; pszTitle : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetFileNameFromBrowse(HWND hwnd, LPWSTR pszFilePath, DWORD cchFilePath, LPCWSTR pszWorkingDir, LPCWSTR pszDefExt, LPCWSTR pszFilters, LPCWSTR pszTitle) #uselib "SHELL32.dll" #cfunc global GetFileNameFromBrowse "GetFileNameFromBrowse" intptr, intptr, int, wstr, wstr, wstr, wstr ; res = GetFileNameFromBrowse(hwnd, varptr(pszFilePath), cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle) ; hwnd : HWND optional -> "intptr" ; pszFilePath : LPWSTR in/out -> "intptr" ; cchFilePath : DWORD -> "int" ; pszWorkingDir : LPCWSTR optional -> "wstr" ; pszDefExt : LPCWSTR -> "wstr" ; pszFilters : LPCWSTR optional -> "wstr" ; pszTitle : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procGetFileNameFromBrowse = shell32.NewProc("GetFileNameFromBrowse")
)
// hwnd (HWND optional), pszFilePath (LPWSTR in/out), cchFilePath (DWORD), pszWorkingDir (LPCWSTR optional), pszDefExt (LPCWSTR), pszFilters (LPCWSTR optional), pszTitle (LPCWSTR optional)
r1, _, err := procGetFileNameFromBrowse.Call(
uintptr(hwnd),
uintptr(pszFilePath),
uintptr(cchFilePath),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszWorkingDir))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszDefExt))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszFilters))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszTitle))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetFileNameFromBrowse(
hwnd: THandle; // HWND optional
pszFilePath: PWideChar; // LPWSTR in/out
cchFilePath: DWORD; // DWORD
pszWorkingDir: PWideChar; // LPCWSTR optional
pszDefExt: PWideChar; // LPCWSTR
pszFilters: PWideChar; // LPCWSTR optional
pszTitle: PWideChar // LPCWSTR optional
): BOOL; stdcall;
external 'SHELL32.dll' name 'GetFileNameFromBrowse';result := DllCall("SHELL32\GetFileNameFromBrowse"
, "Ptr", hwnd ; HWND optional
, "Ptr", pszFilePath ; LPWSTR in/out
, "UInt", cchFilePath ; DWORD
, "WStr", pszWorkingDir ; LPCWSTR optional
, "WStr", pszDefExt ; LPCWSTR
, "WStr", pszFilters ; LPCWSTR optional
, "WStr", pszTitle ; LPCWSTR optional
, "Int") ; return: BOOL●GetFileNameFromBrowse(hwnd, pszFilePath, cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle) = DLL("SHELL32.dll", "bool GetFileNameFromBrowse(void*, char*, dword, char*, char*, char*, char*)")
# 呼び出し: GetFileNameFromBrowse(hwnd, pszFilePath, cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle)
# hwnd : HWND optional -> "void*"
# pszFilePath : LPWSTR in/out -> "char*"
# cchFilePath : DWORD -> "dword"
# pszWorkingDir : LPCWSTR optional -> "char*"
# pszDefExt : LPCWSTR -> "char*"
# pszFilters : LPCWSTR optional -> "char*"
# pszTitle : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。