Win32 API 日本語リファレンス
ホームWeb.InternetExplorer › IEShowOpenFileDialog

IEShowOpenFileDialog

関数
IE保護モードでファイルを開くダイアログを表示する。
DLLIeframe.dll呼出規約winapi

シグネチャ

// Ieframe.dll
#include <windows.h>

HRESULT IEShowOpenFileDialog(
    HWND hwnd,
    LPWSTR lpwstrFileName,
    DWORD cchMaxFileName,
    LPCWSTR lpwstrInitialDir,   // optional
    LPCWSTR lpwstrFilter,   // optional
    LPCWSTR lpwstrDefExt,   // optional
    DWORD dwFilterIndex,
    DWORD dwFlags,
    HANDLE* phFile
);

パラメーター

名前方向説明
hwndHWNDinダイアログの親ウィンドウのハンドル。
lpwstrFileNameLPWSTRinout初期ファイル名を渡し、選択結果を受け取るバッファへのポインタ。
cchMaxFileNameDWORDinlpwstrFileNameバッファに格納できる最大文字数。
lpwstrInitialDirLPCWSTRinoptional初期表示するディレクトリのパス。NULL可。
lpwstrFilterLPCWSTRinoptionalファイルタイプフィルタ文字列(NULL区切り)。
lpwstrDefExtLPCWSTRinoptional拡張子未指定時に付加する既定の拡張子。NULL可。
dwFilterIndexDWORDin初期選択するフィルタの1始まりインデックス。
dwFlagsDWORDinダイアログの動作を制御するフラグ。
phFileHANDLE*out開いたファイルのハンドルを受け取るポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

// Ieframe.dll
#include <windows.h>

HRESULT IEShowOpenFileDialog(
    HWND hwnd,
    LPWSTR lpwstrFileName,
    DWORD cchMaxFileName,
    LPCWSTR lpwstrInitialDir,   // optional
    LPCWSTR lpwstrFilter,   // optional
    LPCWSTR lpwstrDefExt,   // optional
    DWORD dwFilterIndex,
    DWORD dwFlags,
    HANDLE* phFile
);
[DllImport("Ieframe.dll", ExactSpelling = true)]
static extern int IEShowOpenFileDialog(
    IntPtr hwnd,   // HWND
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpwstrFileName,   // LPWSTR in/out
    uint cchMaxFileName,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string lpwstrInitialDir,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpwstrFilter,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpwstrDefExt,   // LPCWSTR optional
    uint dwFilterIndex,   // DWORD
    uint dwFlags,   // DWORD
    IntPtr phFile   // HANDLE* out
);
<DllImport("Ieframe.dll", ExactSpelling:=True)>
Public Shared Function IEShowOpenFileDialog(
    hwnd As IntPtr,   ' HWND
    <MarshalAs(UnmanagedType.LPWStr)> lpwstrFileName As System.Text.StringBuilder,   ' LPWSTR in/out
    cchMaxFileName As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpwstrInitialDir As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpwstrFilter As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpwstrDefExt As String,   ' LPCWSTR optional
    dwFilterIndex As UInteger,   ' DWORD
    dwFlags As UInteger,   ' DWORD
    phFile As IntPtr   ' HANDLE* out
) As Integer
End Function
' hwnd : HWND
' lpwstrFileName : LPWSTR in/out
' cchMaxFileName : DWORD
' lpwstrInitialDir : LPCWSTR optional
' lpwstrFilter : LPCWSTR optional
' lpwstrDefExt : LPCWSTR optional
' dwFilterIndex : DWORD
' dwFlags : DWORD
' phFile : HANDLE* out
Declare PtrSafe Function IEShowOpenFileDialog Lib "ieframe" ( _
    ByVal hwnd As LongPtr, _
    ByVal lpwstrFileName As LongPtr, _
    ByVal cchMaxFileName As Long, _
    ByVal lpwstrInitialDir As LongPtr, _
    ByVal lpwstrFilter As LongPtr, _
    ByVal lpwstrDefExt As LongPtr, _
    ByVal dwFilterIndex As Long, _
    ByVal dwFlags As Long, _
    ByVal phFile As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

IEShowOpenFileDialog = ctypes.windll.ieframe.IEShowOpenFileDialog
IEShowOpenFileDialog.restype = ctypes.c_int
IEShowOpenFileDialog.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND
    wintypes.LPWSTR,  # lpwstrFileName : LPWSTR in/out
    wintypes.DWORD,  # cchMaxFileName : DWORD
    wintypes.LPCWSTR,  # lpwstrInitialDir : LPCWSTR optional
    wintypes.LPCWSTR,  # lpwstrFilter : LPCWSTR optional
    wintypes.LPCWSTR,  # lpwstrDefExt : LPCWSTR optional
    wintypes.DWORD,  # dwFilterIndex : DWORD
    wintypes.DWORD,  # dwFlags : DWORD
    ctypes.c_void_p,  # phFile : HANDLE* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('Ieframe.dll')
IEShowOpenFileDialog = Fiddle::Function.new(
  lib['IEShowOpenFileDialog'],
  [
    Fiddle::TYPE_VOIDP,  # hwnd : HWND
    Fiddle::TYPE_VOIDP,  # lpwstrFileName : LPWSTR in/out
    -Fiddle::TYPE_INT,  # cchMaxFileName : DWORD
    Fiddle::TYPE_VOIDP,  # lpwstrInitialDir : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpwstrFilter : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpwstrDefExt : LPCWSTR optional
    -Fiddle::TYPE_INT,  # dwFilterIndex : DWORD
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_VOIDP,  # phFile : HANDLE* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ieframe")]
extern "system" {
    fn IEShowOpenFileDialog(
        hwnd: *mut core::ffi::c_void,  // HWND
        lpwstrFileName: *mut u16,  // LPWSTR in/out
        cchMaxFileName: u32,  // DWORD
        lpwstrInitialDir: *const u16,  // LPCWSTR optional
        lpwstrFilter: *const u16,  // LPCWSTR optional
        lpwstrDefExt: *const u16,  // LPCWSTR optional
        dwFilterIndex: u32,  // DWORD
        dwFlags: u32,  // DWORD
        phFile: *mut *mut core::ffi::c_void  // HANDLE* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("Ieframe.dll")]
public static extern int IEShowOpenFileDialog(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpwstrFileName, uint cchMaxFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpwstrInitialDir, [MarshalAs(UnmanagedType.LPWStr)] string lpwstrFilter, [MarshalAs(UnmanagedType.LPWStr)] string lpwstrDefExt, uint dwFilterIndex, uint dwFlags, IntPtr phFile);
"@
$api = Add-Type -MemberDefinition $sig -Name 'Ieframe_IEShowOpenFileDialog' -Namespace Win32 -PassThru
# $api::IEShowOpenFileDialog(hwnd, lpwstrFileName, cchMaxFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, phFile)
#uselib "Ieframe.dll"
#func global IEShowOpenFileDialog "IEShowOpenFileDialog" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; IEShowOpenFileDialog hwnd, varptr(lpwstrFileName), cchMaxFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, phFile   ; 戻り値は stat
; hwnd : HWND -> "sptr"
; lpwstrFileName : LPWSTR in/out -> "sptr"
; cchMaxFileName : DWORD -> "sptr"
; lpwstrInitialDir : LPCWSTR optional -> "sptr"
; lpwstrFilter : LPCWSTR optional -> "sptr"
; lpwstrDefExt : LPCWSTR optional -> "sptr"
; dwFilterIndex : DWORD -> "sptr"
; dwFlags : DWORD -> "sptr"
; phFile : HANDLE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "Ieframe.dll"
#cfunc global IEShowOpenFileDialog "IEShowOpenFileDialog" sptr, var, int, wstr, wstr, wstr, int, int, sptr
; res = IEShowOpenFileDialog(hwnd, lpwstrFileName, cchMaxFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, phFile)
; hwnd : HWND -> "sptr"
; lpwstrFileName : LPWSTR in/out -> "var"
; cchMaxFileName : DWORD -> "int"
; lpwstrInitialDir : LPCWSTR optional -> "wstr"
; lpwstrFilter : LPCWSTR optional -> "wstr"
; lpwstrDefExt : LPCWSTR optional -> "wstr"
; dwFilterIndex : DWORD -> "int"
; dwFlags : DWORD -> "int"
; phFile : HANDLE* out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT IEShowOpenFileDialog(HWND hwnd, LPWSTR lpwstrFileName, DWORD cchMaxFileName, LPCWSTR lpwstrInitialDir, LPCWSTR lpwstrFilter, LPCWSTR lpwstrDefExt, DWORD dwFilterIndex, DWORD dwFlags, HANDLE* phFile)
#uselib "Ieframe.dll"
#cfunc global IEShowOpenFileDialog "IEShowOpenFileDialog" intptr, var, int, wstr, wstr, wstr, int, int, intptr
; res = IEShowOpenFileDialog(hwnd, lpwstrFileName, cchMaxFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, phFile)
; hwnd : HWND -> "intptr"
; lpwstrFileName : LPWSTR in/out -> "var"
; cchMaxFileName : DWORD -> "int"
; lpwstrInitialDir : LPCWSTR optional -> "wstr"
; lpwstrFilter : LPCWSTR optional -> "wstr"
; lpwstrDefExt : LPCWSTR optional -> "wstr"
; dwFilterIndex : DWORD -> "int"
; dwFlags : DWORD -> "int"
; phFile : HANDLE* out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ieframe = windows.NewLazySystemDLL("Ieframe.dll")
	procIEShowOpenFileDialog = ieframe.NewProc("IEShowOpenFileDialog")
)

// hwnd (HWND), lpwstrFileName (LPWSTR in/out), cchMaxFileName (DWORD), lpwstrInitialDir (LPCWSTR optional), lpwstrFilter (LPCWSTR optional), lpwstrDefExt (LPCWSTR optional), dwFilterIndex (DWORD), dwFlags (DWORD), phFile (HANDLE* out)
r1, _, err := procIEShowOpenFileDialog.Call(
	uintptr(hwnd),
	uintptr(lpwstrFileName),
	uintptr(cchMaxFileName),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpwstrInitialDir))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpwstrFilter))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpwstrDefExt))),
	uintptr(dwFilterIndex),
	uintptr(dwFlags),
	uintptr(phFile),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function IEShowOpenFileDialog(
  hwnd: THandle;   // HWND
  lpwstrFileName: PWideChar;   // LPWSTR in/out
  cchMaxFileName: DWORD;   // DWORD
  lpwstrInitialDir: PWideChar;   // LPCWSTR optional
  lpwstrFilter: PWideChar;   // LPCWSTR optional
  lpwstrDefExt: PWideChar;   // LPCWSTR optional
  dwFilterIndex: DWORD;   // DWORD
  dwFlags: DWORD;   // DWORD
  phFile: Pointer   // HANDLE* out
): Integer; stdcall;
  external 'Ieframe.dll' name 'IEShowOpenFileDialog';
result := DllCall("Ieframe\IEShowOpenFileDialog"
    , "Ptr", hwnd   ; HWND
    , "Ptr", lpwstrFileName   ; LPWSTR in/out
    , "UInt", cchMaxFileName   ; DWORD
    , "WStr", lpwstrInitialDir   ; LPCWSTR optional
    , "WStr", lpwstrFilter   ; LPCWSTR optional
    , "WStr", lpwstrDefExt   ; LPCWSTR optional
    , "UInt", dwFilterIndex   ; DWORD
    , "UInt", dwFlags   ; DWORD
    , "Ptr", phFile   ; HANDLE* out
    , "Int")   ; return: HRESULT
●IEShowOpenFileDialog(hwnd, lpwstrFileName, cchMaxFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, phFile) = DLL("Ieframe.dll", "int IEShowOpenFileDialog(void*, char*, dword, char*, char*, char*, dword, dword, void*)")
# 呼び出し: IEShowOpenFileDialog(hwnd, lpwstrFileName, cchMaxFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, phFile)
# hwnd : HWND -> "void*"
# lpwstrFileName : LPWSTR in/out -> "char*"
# cchMaxFileName : DWORD -> "dword"
# lpwstrInitialDir : LPCWSTR optional -> "char*"
# lpwstrFilter : LPCWSTR optional -> "char*"
# lpwstrDefExt : LPCWSTR optional -> "char*"
# dwFilterIndex : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# phFile : HANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "ieframe" fn IEShowOpenFileDialog(
    hwnd: ?*anyopaque, // HWND
    lpwstrFileName: [*c]u16, // LPWSTR in/out
    cchMaxFileName: u32, // DWORD
    lpwstrInitialDir: [*c]const u16, // LPCWSTR optional
    lpwstrFilter: [*c]const u16, // LPCWSTR optional
    lpwstrDefExt: [*c]const u16, // LPCWSTR optional
    dwFilterIndex: u32, // DWORD
    dwFlags: u32, // DWORD
    phFile: ?*anyopaque // HANDLE* out
) callconv(std.os.windows.WINAPI) i32;
proc IEShowOpenFileDialog(
    hwnd: pointer,  # HWND
    lpwstrFileName: ptr uint16,  # LPWSTR in/out
    cchMaxFileName: uint32,  # DWORD
    lpwstrInitialDir: WideCString,  # LPCWSTR optional
    lpwstrFilter: WideCString,  # LPCWSTR optional
    lpwstrDefExt: WideCString,  # LPCWSTR optional
    dwFilterIndex: uint32,  # DWORD
    dwFlags: uint32,  # DWORD
    phFile: pointer  # HANDLE* out
): int32 {.importc: "IEShowOpenFileDialog", stdcall, dynlib: "Ieframe.dll".}
pragma(lib, "ieframe");
extern(Windows)
int IEShowOpenFileDialog(
    void* hwnd,   // HWND
    wchar* lpwstrFileName,   // LPWSTR in/out
    uint cchMaxFileName,   // DWORD
    const(wchar)* lpwstrInitialDir,   // LPCWSTR optional
    const(wchar)* lpwstrFilter,   // LPCWSTR optional
    const(wchar)* lpwstrDefExt,   // LPCWSTR optional
    uint dwFilterIndex,   // DWORD
    uint dwFlags,   // DWORD
    void* phFile   // HANDLE* out
);
ccall((:IEShowOpenFileDialog, "Ieframe.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{UInt16}, UInt32, Cwstring, Cwstring, Cwstring, UInt32, UInt32, Ptr{Cvoid}),
      hwnd, lpwstrFileName, cchMaxFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, phFile)
# hwnd : HWND -> Ptr{Cvoid}
# lpwstrFileName : LPWSTR in/out -> Ptr{UInt16}
# cchMaxFileName : DWORD -> UInt32
# lpwstrInitialDir : LPCWSTR optional -> Cwstring
# lpwstrFilter : LPCWSTR optional -> Cwstring
# lpwstrDefExt : LPCWSTR optional -> Cwstring
# dwFilterIndex : DWORD -> UInt32
# dwFlags : DWORD -> UInt32
# phFile : HANDLE* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t IEShowOpenFileDialog(
    void* hwnd,
    uint16_t* lpwstrFileName,
    uint32_t cchMaxFileName,
    const uint16_t* lpwstrInitialDir,
    const uint16_t* lpwstrFilter,
    const uint16_t* lpwstrDefExt,
    uint32_t dwFilterIndex,
    uint32_t dwFlags,
    void* phFile);
]]
local ieframe = ffi.load("ieframe")
-- ieframe.IEShowOpenFileDialog(hwnd, lpwstrFileName, cchMaxFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, phFile)
-- hwnd : HWND
-- lpwstrFileName : LPWSTR in/out
-- cchMaxFileName : DWORD
-- lpwstrInitialDir : LPCWSTR optional
-- lpwstrFilter : LPCWSTR optional
-- lpwstrDefExt : LPCWSTR optional
-- dwFilterIndex : DWORD
-- dwFlags : DWORD
-- phFile : HANDLE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('Ieframe.dll');
const IEShowOpenFileDialog = lib.func('__stdcall', 'IEShowOpenFileDialog', 'int32_t', ['void *', 'uint16_t *', 'uint32_t', 'str16', 'str16', 'str16', 'uint32_t', 'uint32_t', 'void *']);
// IEShowOpenFileDialog(hwnd, lpwstrFileName, cchMaxFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, phFile)
// hwnd : HWND -> 'void *'
// lpwstrFileName : LPWSTR in/out -> 'uint16_t *'
// cchMaxFileName : DWORD -> 'uint32_t'
// lpwstrInitialDir : LPCWSTR optional -> 'str16'
// lpwstrFilter : LPCWSTR optional -> 'str16'
// lpwstrDefExt : LPCWSTR optional -> 'str16'
// dwFilterIndex : DWORD -> 'uint32_t'
// dwFlags : DWORD -> 'uint32_t'
// phFile : HANDLE* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("Ieframe.dll", {
  IEShowOpenFileDialog: { parameters: ["pointer", "buffer", "u32", "buffer", "buffer", "buffer", "u32", "u32", "pointer"], result: "i32" },
});
// lib.symbols.IEShowOpenFileDialog(hwnd, lpwstrFileName, cchMaxFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, phFile)
// hwnd : HWND -> "pointer"
// lpwstrFileName : LPWSTR in/out -> "buffer"
// cchMaxFileName : DWORD -> "u32"
// lpwstrInitialDir : LPCWSTR optional -> "buffer"
// lpwstrFilter : LPCWSTR optional -> "buffer"
// lpwstrDefExt : LPCWSTR optional -> "buffer"
// dwFilterIndex : DWORD -> "u32"
// dwFlags : DWORD -> "u32"
// phFile : HANDLE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t IEShowOpenFileDialog(
    void* hwnd,
    uint16_t* lpwstrFileName,
    uint32_t cchMaxFileName,
    const uint16_t* lpwstrInitialDir,
    const uint16_t* lpwstrFilter,
    const uint16_t* lpwstrDefExt,
    uint32_t dwFilterIndex,
    uint32_t dwFlags,
    void* phFile);
C, "Ieframe.dll");
// $ffi->IEShowOpenFileDialog(hwnd, lpwstrFileName, cchMaxFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, phFile);
// hwnd : HWND
// lpwstrFileName : LPWSTR in/out
// cchMaxFileName : DWORD
// lpwstrInitialDir : LPCWSTR optional
// lpwstrFilter : LPCWSTR optional
// lpwstrDefExt : LPCWSTR optional
// dwFilterIndex : DWORD
// dwFlags : DWORD
// phFile : HANDLE* out
// 構造体/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 Ieframe extends StdCallLibrary {
    Ieframe INSTANCE = Native.load("ieframe", Ieframe.class);
    int IEShowOpenFileDialog(
        Pointer hwnd,   // HWND
        char[] lpwstrFileName,   // LPWSTR in/out
        int cchMaxFileName,   // DWORD
        WString lpwstrInitialDir,   // LPCWSTR optional
        WString lpwstrFilter,   // LPCWSTR optional
        WString lpwstrDefExt,   // LPCWSTR optional
        int dwFilterIndex,   // DWORD
        int dwFlags,   // DWORD
        Pointer phFile   // HANDLE* out
    );
}
@[Link("ieframe")]
lib LibIeframe
  fun IEShowOpenFileDialog = IEShowOpenFileDialog(
    hwnd : Void*,   # HWND
    lpwstrFileName : UInt16*,   # LPWSTR in/out
    cchMaxFileName : UInt32,   # DWORD
    lpwstrInitialDir : UInt16*,   # LPCWSTR optional
    lpwstrFilter : UInt16*,   # LPCWSTR optional
    lpwstrDefExt : UInt16*,   # LPCWSTR optional
    dwFilterIndex : UInt32,   # DWORD
    dwFlags : UInt32,   # DWORD
    phFile : Void*   # HANDLE* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef IEShowOpenFileDialogNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Uint32, Pointer<Void>);
typedef IEShowOpenFileDialogDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, int, Pointer<Void>);
final IEShowOpenFileDialog = DynamicLibrary.open('Ieframe.dll')
    .lookupFunction<IEShowOpenFileDialogNative, IEShowOpenFileDialogDart>('IEShowOpenFileDialog');
// hwnd : HWND -> Pointer<Void>
// lpwstrFileName : LPWSTR in/out -> Pointer<Utf16>
// cchMaxFileName : DWORD -> Uint32
// lpwstrInitialDir : LPCWSTR optional -> Pointer<Utf16>
// lpwstrFilter : LPCWSTR optional -> Pointer<Utf16>
// lpwstrDefExt : LPCWSTR optional -> Pointer<Utf16>
// dwFilterIndex : DWORD -> Uint32
// dwFlags : DWORD -> Uint32
// phFile : HANDLE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function IEShowOpenFileDialog(
  hwnd: THandle;   // HWND
  lpwstrFileName: PWideChar;   // LPWSTR in/out
  cchMaxFileName: DWORD;   // DWORD
  lpwstrInitialDir: PWideChar;   // LPCWSTR optional
  lpwstrFilter: PWideChar;   // LPCWSTR optional
  lpwstrDefExt: PWideChar;   // LPCWSTR optional
  dwFilterIndex: DWORD;   // DWORD
  dwFlags: DWORD;   // DWORD
  phFile: Pointer   // HANDLE* out
): Integer; stdcall;
  external 'Ieframe.dll' name 'IEShowOpenFileDialog';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "IEShowOpenFileDialog"
  c_IEShowOpenFileDialog :: Ptr () -> CWString -> Word32 -> CWString -> CWString -> CWString -> Word32 -> Word32 -> Ptr () -> IO Int32
-- hwnd : HWND -> Ptr ()
-- lpwstrFileName : LPWSTR in/out -> CWString
-- cchMaxFileName : DWORD -> Word32
-- lpwstrInitialDir : LPCWSTR optional -> CWString
-- lpwstrFilter : LPCWSTR optional -> CWString
-- lpwstrDefExt : LPCWSTR optional -> CWString
-- dwFilterIndex : DWORD -> Word32
-- dwFlags : DWORD -> Word32
-- phFile : HANDLE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ieshowopenfiledialog =
  foreign "IEShowOpenFileDialog"
    ((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hwnd : HWND -> (ptr void) *)
(* lpwstrFileName : LPWSTR in/out -> (ptr uint16_t) *)
(* cchMaxFileName : DWORD -> uint32_t *)
(* lpwstrInitialDir : LPCWSTR optional -> (ptr uint16_t) *)
(* lpwstrFilter : LPCWSTR optional -> (ptr uint16_t) *)
(* lpwstrDefExt : LPCWSTR optional -> (ptr uint16_t) *)
(* dwFilterIndex : DWORD -> uint32_t *)
(* dwFlags : DWORD -> uint32_t *)
(* phFile : HANDLE* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ieframe (t "Ieframe.dll"))
(cffi:use-foreign-library ieframe)

(cffi:defcfun ("IEShowOpenFileDialog" ieshow-open-file-dialog :convention :stdcall) :int32
  (hwnd :pointer)   ; HWND
  (lpwstr-file-name :pointer)   ; LPWSTR in/out
  (cch-max-file-name :uint32)   ; DWORD
  (lpwstr-initial-dir (:string :encoding :utf-16le))   ; LPCWSTR optional
  (lpwstr-filter (:string :encoding :utf-16le))   ; LPCWSTR optional
  (lpwstr-def-ext (:string :encoding :utf-16le))   ; LPCWSTR optional
  (dw-filter-index :uint32)   ; DWORD
  (dw-flags :uint32)   ; DWORD
  (ph-file :pointer))   ; HANDLE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $IEShowOpenFileDialog = Win32::API::More->new('Ieframe',
    'int IEShowOpenFileDialog(HANDLE hwnd, LPWSTR lpwstrFileName, DWORD cchMaxFileName, LPCWSTR lpwstrInitialDir, LPCWSTR lpwstrFilter, LPCWSTR lpwstrDefExt, DWORD dwFilterIndex, DWORD dwFlags, HANDLE phFile)');
# my $ret = $IEShowOpenFileDialog->Call($hwnd, $lpwstrFileName, $cchMaxFileName, $lpwstrInitialDir, $lpwstrFilter, $lpwstrDefExt, $dwFilterIndex, $dwFlags, $phFile);
# hwnd : HWND -> HANDLE
# lpwstrFileName : LPWSTR in/out -> LPWSTR
# cchMaxFileName : DWORD -> DWORD
# lpwstrInitialDir : LPCWSTR optional -> LPCWSTR
# lpwstrFilter : LPCWSTR optional -> LPCWSTR
# lpwstrDefExt : LPCWSTR optional -> LPCWSTR
# dwFilterIndex : DWORD -> DWORD
# dwFlags : DWORD -> DWORD
# phFile : HANDLE* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。