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 | ダイアログ ボックスを所有するウィンドウへのハンドル。このメンバーには任意の有効なウィンドウ ハンドルを指定できます。ダイアログ ボックスに所有者がない場合は NULL を指定できます。 |
| pszFilePath | LPWSTR | inout | ファイル名編集コントロールの初期化に使用されるファイル名を含む、null 終端の Unicode 文字列。この文字列は OPENFILENAME 構造体の lpstrFile メンバーに対応しており、まったく同じ方法で使用されます。 |
| cchFilePath | DWORD | in | 終端の null 文字を含む pszFilePath の文字数。 |
| pszWorkingDir | LPCWSTR | inoptional | 初期ディレクトリの完全修飾ファイル パス。この文字列は OPENFILENAME 構造体の lpstrInitialDir メンバーに対応しており、まったく同じ方法で使用されます。 |
| pszDefExt | LPCWSTR | in | 既定のファイル名拡張子を含む、null 終端の Unicode 文字列。ユーザーが拡張子を指定しない場合、この拡張子が pszFilePath に追加されます。文字列には '.' 文字を含めないでください。この文字列が NULL で、ユーザーが拡張子を入力しなかった場合は、拡張子は追加されません。 |
| pszFilters | LPCWSTR | inoptional | フィルターを定義する、null 終端の Unicode 文字列。この文字列は OPENFILENAME 構造体の lpstrFilter メンバーに対応しており、まったく同じ方法で使用されます。 |
| pszTitle | LPCWSTR | inoptional | ダイアログ ボックスのタイトル バーに表示される、null 終端の Unicode 文字列。この値が NULL の場合、システムは既定のタイトルを使用します。 |
戻り値の型: BOOL
公式ドキュメント
GetFileNameFromBrowse 関数は、ユーザーが開くファイルのドライブ、ディレクトリ、および名前を指定できるように、[ファイルを開く] ダイアログ ボックスを作成します。
戻り値
型: BOOL
ユーザーがファイル名を指定して [OK] をクリックした場合、戻り値は TRUE です。pszFilePath が指すバッファーには、ユーザーが指定した完全なパスとファイル名が格納されます。ユーザーが [ファイルを開く] ダイアログ ボックスをキャンセルまたは閉じた場合、あるいはエラーが発生した場合、戻り値は FALSE です。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 <MarshalAs(UnmanagedType.Bool)> 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)。const std = @import("std");
extern "shell32" fn GetFileNameFromBrowse(
hwnd: ?*anyopaque, // HWND optional
pszFilePath: [*c]u16, // LPWSTR in/out
cchFilePath: u32, // DWORD
pszWorkingDir: [*c]const u16, // LPCWSTR optional
pszDefExt: [*c]const u16, // LPCWSTR
pszFilters: [*c]const u16, // LPCWSTR optional
pszTitle: [*c]const u16 // LPCWSTR optional
) callconv(std.os.windows.WINAPI) i32;proc GetFileNameFromBrowse(
hwnd: pointer, # HWND optional
pszFilePath: ptr uint16, # LPWSTR in/out
cchFilePath: uint32, # DWORD
pszWorkingDir: WideCString, # LPCWSTR optional
pszDefExt: WideCString, # LPCWSTR
pszFilters: WideCString, # LPCWSTR optional
pszTitle: WideCString # LPCWSTR optional
): int32 {.importc: "GetFileNameFromBrowse", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
int GetFileNameFromBrowse(
void* hwnd, // HWND optional
wchar* pszFilePath, // LPWSTR in/out
uint cchFilePath, // DWORD
const(wchar)* pszWorkingDir, // LPCWSTR optional
const(wchar)* pszDefExt, // LPCWSTR
const(wchar)* pszFilters, // LPCWSTR optional
const(wchar)* pszTitle // LPCWSTR optional
);ccall((:GetFileNameFromBrowse, "SHELL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{UInt16}, UInt32, Cwstring, Cwstring, Cwstring, Cwstring),
hwnd, pszFilePath, cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle)
# hwnd : HWND optional -> Ptr{Cvoid}
# pszFilePath : LPWSTR in/out -> Ptr{UInt16}
# cchFilePath : DWORD -> UInt32
# pszWorkingDir : LPCWSTR optional -> Cwstring
# pszDefExt : LPCWSTR -> Cwstring
# pszFilters : LPCWSTR optional -> Cwstring
# pszTitle : LPCWSTR optional -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetFileNameFromBrowse(
void* hwnd,
uint16_t* pszFilePath,
uint32_t cchFilePath,
const uint16_t* pszWorkingDir,
const uint16_t* pszDefExt,
const uint16_t* pszFilters,
const uint16_t* pszTitle);
]]
local shell32 = ffi.load("shell32")
-- shell32.GetFileNameFromBrowse(hwnd, pszFilePath, cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle)
-- hwnd : HWND optional
-- pszFilePath : LPWSTR in/out
-- cchFilePath : DWORD
-- pszWorkingDir : LPCWSTR optional
-- pszDefExt : LPCWSTR
-- pszFilters : LPCWSTR optional
-- pszTitle : LPCWSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const GetFileNameFromBrowse = lib.func('__stdcall', 'GetFileNameFromBrowse', 'int32_t', ['void *', 'uint16_t *', 'uint32_t', 'str16', 'str16', 'str16', 'str16']);
// GetFileNameFromBrowse(hwnd, pszFilePath, cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle)
// hwnd : HWND optional -> 'void *'
// pszFilePath : LPWSTR in/out -> 'uint16_t *'
// cchFilePath : DWORD -> 'uint32_t'
// pszWorkingDir : LPCWSTR optional -> 'str16'
// pszDefExt : LPCWSTR -> 'str16'
// pszFilters : LPCWSTR optional -> 'str16'
// pszTitle : LPCWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
GetFileNameFromBrowse: { parameters: ["pointer", "buffer", "u32", "buffer", "buffer", "buffer", "buffer"], result: "i32" },
});
// lib.symbols.GetFileNameFromBrowse(hwnd, pszFilePath, cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle)
// hwnd : HWND optional -> "pointer"
// pszFilePath : LPWSTR in/out -> "buffer"
// cchFilePath : DWORD -> "u32"
// pszWorkingDir : LPCWSTR optional -> "buffer"
// pszDefExt : LPCWSTR -> "buffer"
// pszFilters : LPCWSTR optional -> "buffer"
// pszTitle : LPCWSTR optional -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetFileNameFromBrowse(
void* hwnd,
uint16_t* pszFilePath,
uint32_t cchFilePath,
const uint16_t* pszWorkingDir,
const uint16_t* pszDefExt,
const uint16_t* pszFilters,
const uint16_t* pszTitle);
C, "SHELL32.dll");
// $ffi->GetFileNameFromBrowse(hwnd, pszFilePath, cchFilePath, pszWorkingDir, pszDefExt, pszFilters, pszTitle);
// hwnd : HWND optional
// pszFilePath : LPWSTR in/out
// cchFilePath : DWORD
// pszWorkingDir : LPCWSTR optional
// pszDefExt : LPCWSTR
// pszFilters : LPCWSTR optional
// pszTitle : LPCWSTR optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.load("shell32", Shell32.class);
boolean GetFileNameFromBrowse(
Pointer hwnd, // HWND optional
char[] pszFilePath, // LPWSTR in/out
int cchFilePath, // DWORD
WString pszWorkingDir, // LPCWSTR optional
WString pszDefExt, // LPCWSTR
WString pszFilters, // LPCWSTR optional
WString pszTitle // LPCWSTR optional
);
}@[Link("shell32")]
lib LibSHELL32
fun GetFileNameFromBrowse = GetFileNameFromBrowse(
hwnd : Void*, # HWND optional
pszFilePath : UInt16*, # LPWSTR in/out
cchFilePath : UInt32, # DWORD
pszWorkingDir : UInt16*, # LPCWSTR optional
pszDefExt : UInt16*, # LPCWSTR
pszFilters : UInt16*, # LPCWSTR optional
pszTitle : UInt16* # LPCWSTR optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetFileNameFromBrowseNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
typedef GetFileNameFromBrowseDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
final GetFileNameFromBrowse = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<GetFileNameFromBrowseNative, GetFileNameFromBrowseDart>('GetFileNameFromBrowse');
// hwnd : HWND optional -> Pointer<Void>
// pszFilePath : LPWSTR in/out -> Pointer<Utf16>
// cchFilePath : DWORD -> Uint32
// pszWorkingDir : LPCWSTR optional -> Pointer<Utf16>
// pszDefExt : LPCWSTR -> Pointer<Utf16>
// pszFilters : LPCWSTR optional -> Pointer<Utf16>
// pszTitle : LPCWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetFileNameFromBrowse"
c_GetFileNameFromBrowse :: Ptr () -> CWString -> Word32 -> CWString -> CWString -> CWString -> CWString -> IO CInt
-- hwnd : HWND optional -> Ptr ()
-- pszFilePath : LPWSTR in/out -> CWString
-- cchFilePath : DWORD -> Word32
-- pszWorkingDir : LPCWSTR optional -> CWString
-- pszDefExt : LPCWSTR -> CWString
-- pszFilters : LPCWSTR optional -> CWString
-- pszTitle : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getfilenamefrombrowse =
foreign "GetFileNameFromBrowse"
((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning int32_t)
(* hwnd : HWND optional -> (ptr void) *)
(* pszFilePath : LPWSTR in/out -> (ptr uint16_t) *)
(* cchFilePath : DWORD -> uint32_t *)
(* pszWorkingDir : LPCWSTR optional -> (ptr uint16_t) *)
(* pszDefExt : LPCWSTR -> (ptr uint16_t) *)
(* pszFilters : LPCWSTR optional -> (ptr uint16_t) *)
(* pszTitle : LPCWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("GetFileNameFromBrowse" get-file-name-from-browse :convention :stdcall) :int32
(hwnd :pointer) ; HWND optional
(psz-file-path :pointer) ; LPWSTR in/out
(cch-file-path :uint32) ; DWORD
(psz-working-dir (:string :encoding :utf-16le)) ; LPCWSTR optional
(psz-def-ext (:string :encoding :utf-16le)) ; LPCWSTR
(psz-filters (:string :encoding :utf-16le)) ; LPCWSTR optional
(psz-title (:string :encoding :utf-16le))) ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetFileNameFromBrowse = Win32::API::More->new('SHELL32',
'BOOL GetFileNameFromBrowse(HANDLE hwnd, LPWSTR pszFilePath, DWORD cchFilePath, LPCWSTR pszWorkingDir, LPCWSTR pszDefExt, LPCWSTR pszFilters, LPCWSTR pszTitle)');
# my $ret = $GetFileNameFromBrowse->Call($hwnd, $pszFilePath, $cchFilePath, $pszWorkingDir, $pszDefExt, $pszFilters, $pszTitle);
# hwnd : HWND optional -> HANDLE
# pszFilePath : LPWSTR in/out -> LPWSTR
# cchFilePath : DWORD -> DWORD
# pszWorkingDir : LPCWSTR optional -> LPCWSTR
# pszDefExt : LPCWSTR -> LPCWSTR
# pszFilters : LPCWSTR optional -> LPCWSTR
# pszTitle : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetOpenFileNameW — ファイルを開くための共通ダイアログを表示する(Unicode版)。