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

IEShowSaveFileDialog

関数
IE保護モードで名前を付けて保存ダイアログを表示する。
DLLIeframe.dll呼出規約winapi

シグネチャ

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

HRESULT IEShowSaveFileDialog(
    HWND hwnd,
    LPCWSTR lpwstrInitialFileName,
    LPCWSTR lpwstrInitialDir,   // optional
    LPCWSTR lpwstrFilter,   // optional
    LPCWSTR lpwstrDefExt,   // optional
    DWORD dwFilterIndex,
    DWORD dwFlags,
    LPWSTR* lppwstrDestinationFilePath,
    HANDLE* phState
);

パラメーター

名前方向説明
hwndHWNDinダイアログの親ウィンドウのハンドル。
lpwstrInitialFileNameLPCWSTRin初期表示するファイル名。
lpwstrInitialDirLPCWSTRinoptional初期表示するディレクトリのパス。NULL可。
lpwstrFilterLPCWSTRinoptionalファイルタイプフィルタ文字列(NULL区切り)。
lpwstrDefExtLPCWSTRinoptional拡張子未指定時に付加する既定の拡張子。NULL可。
dwFilterIndexDWORDin初期選択するフィルタの1始まりインデックス。
dwFlagsDWORDinダイアログの動作を制御するフラグ。
lppwstrDestinationFilePathLPWSTR*out選択された保存先ファイルパスを受け取る出力ポインタ。
phStateHANDLE*out後続の保存操作で使う状態ハンドルを受け取るポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT IEShowSaveFileDialog(
    HWND hwnd,
    LPCWSTR lpwstrInitialFileName,
    LPCWSTR lpwstrInitialDir,   // optional
    LPCWSTR lpwstrFilter,   // optional
    LPCWSTR lpwstrDefExt,   // optional
    DWORD dwFilterIndex,
    DWORD dwFlags,
    LPWSTR* lppwstrDestinationFilePath,
    HANDLE* phState
);
[DllImport("Ieframe.dll", ExactSpelling = true)]
static extern int IEShowSaveFileDialog(
    IntPtr hwnd,   // HWND
    [MarshalAs(UnmanagedType.LPWStr)] string lpwstrInitialFileName,   // LPCWSTR
    [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 lppwstrDestinationFilePath,   // LPWSTR* out
    IntPtr phState   // HANDLE* out
);
<DllImport("Ieframe.dll", ExactSpelling:=True)>
Public Shared Function IEShowSaveFileDialog(
    hwnd As IntPtr,   ' HWND
    <MarshalAs(UnmanagedType.LPWStr)> lpwstrInitialFileName As String,   ' LPCWSTR
    <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
    lppwstrDestinationFilePath As IntPtr,   ' LPWSTR* out
    phState As IntPtr   ' HANDLE* out
) As Integer
End Function
' hwnd : HWND
' lpwstrInitialFileName : LPCWSTR
' lpwstrInitialDir : LPCWSTR optional
' lpwstrFilter : LPCWSTR optional
' lpwstrDefExt : LPCWSTR optional
' dwFilterIndex : DWORD
' dwFlags : DWORD
' lppwstrDestinationFilePath : LPWSTR* out
' phState : HANDLE* out
Declare PtrSafe Function IEShowSaveFileDialog Lib "ieframe" ( _
    ByVal hwnd As LongPtr, _
    ByVal lpwstrInitialFileName As LongPtr, _
    ByVal lpwstrInitialDir As LongPtr, _
    ByVal lpwstrFilter As LongPtr, _
    ByVal lpwstrDefExt As LongPtr, _
    ByVal dwFilterIndex As Long, _
    ByVal dwFlags As Long, _
    ByVal lppwstrDestinationFilePath As LongPtr, _
    ByVal phState As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

IEShowSaveFileDialog = ctypes.windll.ieframe.IEShowSaveFileDialog
IEShowSaveFileDialog.restype = ctypes.c_int
IEShowSaveFileDialog.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND
    wintypes.LPCWSTR,  # lpwstrInitialFileName : LPCWSTR
    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,  # lppwstrDestinationFilePath : LPWSTR* out
    ctypes.c_void_p,  # phState : HANDLE* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ieframe = windows.NewLazySystemDLL("Ieframe.dll")
	procIEShowSaveFileDialog = ieframe.NewProc("IEShowSaveFileDialog")
)

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

extern "ieframe" fn IEShowSaveFileDialog(
    hwnd: ?*anyopaque, // HWND
    lpwstrInitialFileName: [*c]const u16, // LPCWSTR
    lpwstrInitialDir: [*c]const u16, // LPCWSTR optional
    lpwstrFilter: [*c]const u16, // LPCWSTR optional
    lpwstrDefExt: [*c]const u16, // LPCWSTR optional
    dwFilterIndex: u32, // DWORD
    dwFlags: u32, // DWORD
    lppwstrDestinationFilePath: [*c][*c]u16, // LPWSTR* out
    phState: ?*anyopaque // HANDLE* out
) callconv(std.os.windows.WINAPI) i32;
proc IEShowSaveFileDialog(
    hwnd: pointer,  # HWND
    lpwstrInitialFileName: WideCString,  # LPCWSTR
    lpwstrInitialDir: WideCString,  # LPCWSTR optional
    lpwstrFilter: WideCString,  # LPCWSTR optional
    lpwstrDefExt: WideCString,  # LPCWSTR optional
    dwFilterIndex: uint32,  # DWORD
    dwFlags: uint32,  # DWORD
    lppwstrDestinationFilePath: ptr WideCString,  # LPWSTR* out
    phState: pointer  # HANDLE* out
): int32 {.importc: "IEShowSaveFileDialog", stdcall, dynlib: "Ieframe.dll".}
pragma(lib, "ieframe");
extern(Windows)
int IEShowSaveFileDialog(
    void* hwnd,   // HWND
    const(wchar)* lpwstrInitialFileName,   // LPCWSTR
    const(wchar)* lpwstrInitialDir,   // LPCWSTR optional
    const(wchar)* lpwstrFilter,   // LPCWSTR optional
    const(wchar)* lpwstrDefExt,   // LPCWSTR optional
    uint dwFilterIndex,   // DWORD
    uint dwFlags,   // DWORD
    wchar** lppwstrDestinationFilePath,   // LPWSTR* out
    void* phState   // HANDLE* out
);
ccall((:IEShowSaveFileDialog, "Ieframe.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cwstring, Cwstring, Cwstring, Cwstring, UInt32, UInt32, Ptr{Ptr{UInt16}}, Ptr{Cvoid}),
      hwnd, lpwstrInitialFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, lppwstrDestinationFilePath, phState)
# hwnd : HWND -> Ptr{Cvoid}
# lpwstrInitialFileName : LPCWSTR -> Cwstring
# lpwstrInitialDir : LPCWSTR optional -> Cwstring
# lpwstrFilter : LPCWSTR optional -> Cwstring
# lpwstrDefExt : LPCWSTR optional -> Cwstring
# dwFilterIndex : DWORD -> UInt32
# dwFlags : DWORD -> UInt32
# lppwstrDestinationFilePath : LPWSTR* out -> Ptr{Ptr{UInt16}}
# phState : HANDLE* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t IEShowSaveFileDialog(
    void* hwnd,
    const uint16_t* lpwstrInitialFileName,
    const uint16_t* lpwstrInitialDir,
    const uint16_t* lpwstrFilter,
    const uint16_t* lpwstrDefExt,
    uint32_t dwFilterIndex,
    uint32_t dwFlags,
    uint16_t** lppwstrDestinationFilePath,
    void* phState);
]]
local ieframe = ffi.load("ieframe")
-- ieframe.IEShowSaveFileDialog(hwnd, lpwstrInitialFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, lppwstrDestinationFilePath, phState)
-- hwnd : HWND
-- lpwstrInitialFileName : LPCWSTR
-- lpwstrInitialDir : LPCWSTR optional
-- lpwstrFilter : LPCWSTR optional
-- lpwstrDefExt : LPCWSTR optional
-- dwFilterIndex : DWORD
-- dwFlags : DWORD
-- lppwstrDestinationFilePath : LPWSTR* out
-- phState : HANDLE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('Ieframe.dll');
const IEShowSaveFileDialog = lib.func('__stdcall', 'IEShowSaveFileDialog', 'int32_t', ['void *', 'str16', 'str16', 'str16', 'str16', 'uint32_t', 'uint32_t', 'void *', 'void *']);
// IEShowSaveFileDialog(hwnd, lpwstrInitialFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, lppwstrDestinationFilePath, phState)
// hwnd : HWND -> 'void *'
// lpwstrInitialFileName : LPCWSTR -> 'str16'
// lpwstrInitialDir : LPCWSTR optional -> 'str16'
// lpwstrFilter : LPCWSTR optional -> 'str16'
// lpwstrDefExt : LPCWSTR optional -> 'str16'
// dwFilterIndex : DWORD -> 'uint32_t'
// dwFlags : DWORD -> 'uint32_t'
// lppwstrDestinationFilePath : LPWSTR* out -> 'void *'
// phState : HANDLE* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("Ieframe.dll", {
  IEShowSaveFileDialog: { parameters: ["pointer", "buffer", "buffer", "buffer", "buffer", "u32", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.IEShowSaveFileDialog(hwnd, lpwstrInitialFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, lppwstrDestinationFilePath, phState)
// hwnd : HWND -> "pointer"
// lpwstrInitialFileName : LPCWSTR -> "buffer"
// lpwstrInitialDir : LPCWSTR optional -> "buffer"
// lpwstrFilter : LPCWSTR optional -> "buffer"
// lpwstrDefExt : LPCWSTR optional -> "buffer"
// dwFilterIndex : DWORD -> "u32"
// dwFlags : DWORD -> "u32"
// lppwstrDestinationFilePath : LPWSTR* out -> "pointer"
// phState : HANDLE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t IEShowSaveFileDialog(
    void* hwnd,
    const uint16_t* lpwstrInitialFileName,
    const uint16_t* lpwstrInitialDir,
    const uint16_t* lpwstrFilter,
    const uint16_t* lpwstrDefExt,
    uint32_t dwFilterIndex,
    uint32_t dwFlags,
    uint16_t** lppwstrDestinationFilePath,
    void* phState);
C, "Ieframe.dll");
// $ffi->IEShowSaveFileDialog(hwnd, lpwstrInitialFileName, lpwstrInitialDir, lpwstrFilter, lpwstrDefExt, dwFilterIndex, dwFlags, lppwstrDestinationFilePath, phState);
// hwnd : HWND
// lpwstrInitialFileName : LPCWSTR
// lpwstrInitialDir : LPCWSTR optional
// lpwstrFilter : LPCWSTR optional
// lpwstrDefExt : LPCWSTR optional
// dwFilterIndex : DWORD
// dwFlags : DWORD
// lppwstrDestinationFilePath : LPWSTR* out
// phState : 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 IEShowSaveFileDialog(
        Pointer hwnd,   // HWND
        WString lpwstrInitialFileName,   // LPCWSTR
        WString lpwstrInitialDir,   // LPCWSTR optional
        WString lpwstrFilter,   // LPCWSTR optional
        WString lpwstrDefExt,   // LPCWSTR optional
        int dwFilterIndex,   // DWORD
        int dwFlags,   // DWORD
        PointerByReference lppwstrDestinationFilePath,   // LPWSTR* out
        Pointer phState   // HANDLE* out
    );
}
@[Link("ieframe")]
lib LibIeframe
  fun IEShowSaveFileDialog = IEShowSaveFileDialog(
    hwnd : Void*,   # HWND
    lpwstrInitialFileName : UInt16*,   # LPCWSTR
    lpwstrInitialDir : UInt16*,   # LPCWSTR optional
    lpwstrFilter : UInt16*,   # LPCWSTR optional
    lpwstrDefExt : UInt16*,   # LPCWSTR optional
    dwFilterIndex : UInt32,   # DWORD
    dwFlags : UInt32,   # DWORD
    lppwstrDestinationFilePath : UInt16**,   # LPWSTR* out
    phState : 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 IEShowSaveFileDialogNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Uint32, Pointer<Pointer<Utf16>>, Pointer<Void>);
typedef IEShowSaveFileDialogDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, int, Pointer<Pointer<Utf16>>, Pointer<Void>);
final IEShowSaveFileDialog = DynamicLibrary.open('Ieframe.dll')
    .lookupFunction<IEShowSaveFileDialogNative, IEShowSaveFileDialogDart>('IEShowSaveFileDialog');
// hwnd : HWND -> Pointer<Void>
// lpwstrInitialFileName : LPCWSTR -> Pointer<Utf16>
// lpwstrInitialDir : LPCWSTR optional -> Pointer<Utf16>
// lpwstrFilter : LPCWSTR optional -> Pointer<Utf16>
// lpwstrDefExt : LPCWSTR optional -> Pointer<Utf16>
// dwFilterIndex : DWORD -> Uint32
// dwFlags : DWORD -> Uint32
// lppwstrDestinationFilePath : LPWSTR* out -> Pointer<Pointer<Utf16>>
// phState : HANDLE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function IEShowSaveFileDialog(
  hwnd: THandle;   // HWND
  lpwstrInitialFileName: PWideChar;   // LPCWSTR
  lpwstrInitialDir: PWideChar;   // LPCWSTR optional
  lpwstrFilter: PWideChar;   // LPCWSTR optional
  lpwstrDefExt: PWideChar;   // LPCWSTR optional
  dwFilterIndex: DWORD;   // DWORD
  dwFlags: DWORD;   // DWORD
  lppwstrDestinationFilePath: PPWideChar;   // LPWSTR* out
  phState: Pointer   // HANDLE* out
): Integer; stdcall;
  external 'Ieframe.dll' name 'IEShowSaveFileDialog';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let ieshowsavefiledialog =
  foreign "IEShowSaveFileDialog"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr (ptr uint16_t)) @-> (ptr void) @-> returning int32_t)
(* hwnd : HWND -> (ptr void) *)
(* lpwstrInitialFileName : LPCWSTR -> (ptr uint16_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 *)
(* lppwstrDestinationFilePath : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* phState : 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 ("IEShowSaveFileDialog" ieshow-save-file-dialog :convention :stdcall) :int32
  (hwnd :pointer)   ; HWND
  (lpwstr-initial-file-name (:string :encoding :utf-16le))   ; LPCWSTR
  (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
  (lppwstr-destination-file-path :pointer)   ; LPWSTR* out
  (ph-state :pointer))   ; HANDLE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $IEShowSaveFileDialog = Win32::API::More->new('Ieframe',
    'int IEShowSaveFileDialog(HANDLE hwnd, LPCWSTR lpwstrInitialFileName, LPCWSTR lpwstrInitialDir, LPCWSTR lpwstrFilter, LPCWSTR lpwstrDefExt, DWORD dwFilterIndex, DWORD dwFlags, LPVOID lppwstrDestinationFilePath, HANDLE phState)');
# my $ret = $IEShowSaveFileDialog->Call($hwnd, $lpwstrInitialFileName, $lpwstrInitialDir, $lpwstrFilter, $lpwstrDefExt, $dwFilterIndex, $dwFlags, $lppwstrDestinationFilePath, $phState);
# hwnd : HWND -> HANDLE
# lpwstrInitialFileName : LPCWSTR -> LPCWSTR
# lpwstrInitialDir : LPCWSTR optional -> LPCWSTR
# lpwstrFilter : LPCWSTR optional -> LPCWSTR
# lpwstrDefExt : LPCWSTR optional -> LPCWSTR
# dwFilterIndex : DWORD -> DWORD
# dwFlags : DWORD -> DWORD
# lppwstrDestinationFilePath : LPWSTR* out -> LPVOID
# phState : HANDLE* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。