TaskDialog
関数シグネチャ
// COMCTL32.dll
#include <windows.h>
HRESULT TaskDialog(
HWND hwndOwner, // optional
HINSTANCE hInstance, // optional
LPCWSTR pszWindowTitle, // optional
LPCWSTR pszMainInstruction, // optional
LPCWSTR pszContent, // optional
TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons,
LPCWSTR pszIcon, // optional
INT* pnButton // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hwndOwner | HWND | inoptional | 作成するタスク ダイアログのオーナー ウィンドウへのハンドル。このパラメーターが NULL の場合、タスク ダイアログにはオーナー ウィンドウがありません。 | ||||||||||||||||
| hInstance | HINSTANCE | inoptional | pszIcon メンバーで指定されるアイコン リソース、および pszWindowTitle と pszMainInstruction メンバーで指定される文字列リソースを含むモジュールへのハンドル。このパラメーターが NULL の場合、pszIcon は NULL であるか、システム リソース識別子(例: TD_ERROR_ICON)を含む、null 終端の Unicode 文字列へのポインターである必要があります。 | ||||||||||||||||
| pszWindowTitle | LPCWSTR | inoptional | タスク ダイアログのタイトルに使用する文字列へのポインター。このパラメーターは、テキストまたは MAKEINTRESOURCE マクロを通じて渡される整数リソース識別子のいずれかを含む、null 終端の Unicode 文字列です。このパラメーターが NULL の場合、実行可能プログラムのファイル名が使用されます。 | ||||||||||||||||
| pszMainInstruction | LPCWSTR | inoptional | メインの指示文に使用する文字列へのポインター。このパラメーターは、テキストまたは MAKEINTRESOURCE マクロを通じて渡される整数リソース識別子のいずれかを含む、null 終端の Unicode 文字列です。メインの指示文が不要な場合、このパラメーターは NULL にできます。 | ||||||||||||||||
| pszContent | LPCWSTR | inoptional | メインの指示文の下に、より小さいフォントで表示される追加テキストに使用する文字列へのポインター。このパラメーターは、テキストまたは MAKEINTRESOURCE マクロを通じて渡される整数リソース識別子のいずれかを含む、null 終端の Unicode 文字列です。追加テキストが不要な場合は NULL にできます。 | ||||||||||||||||
| dwCommonButtons | TASKDIALOG_COMMON_BUTTON_FLAGS | in | ダイアログ ボックスに表示するプッシュ ボタンを指定します。このパラメーターには、次のグループのフラグの組み合わせを指定できます。 注 ボタンが指定されていない場合、ダイアログ ボックスには既定で OK ボタンが含まれます。
| ||||||||||||||||
| pszIcon | LPCWSTR | inoptional | タスク ダイアログに表示するアイコンを指定する文字列へのポインター。このパラメーターは、MAKEINTRESOURCE マクロに渡される整数リソース識別子か、次の定義済みの値のいずれかである必要があります。このパラメーターが NULL の場合、アイコンは表示されません。hInstance パラメーターが NULL で、かつ定義済みの値のいずれも使用されていない場合、TaskDialog 関数は失敗します。
| ||||||||||||||||
| pnButton | INT* | outoptional | この関数が戻るとき、次のいずれかの値を受け取る整数の格納場所へのポインターを含みます。
この値が NULL の場合、値は返されません。 |
戻り値の型: HRESULT
公式ドキュメント
TaskDialog 関数は、タスク ダイアログを作成、表示、操作します。
戻り値
型: HRESULT
この関数は、次のいずれかの値を返すことができます。
| 戻り値 | 説明 |
|---|---|
| 操作が正常に完了しました。 | |
| 操作を完了するためのメモリが不足しています。 | |
| 1 つ以上の引数が無効です。 | |
| 操作が失敗しました。 |
解説(Remarks)
システムのメモリが不足していることを示すためにタスク ダイアログ ボックスを使用する場合、リソースの読み込みが失敗する可能性があるため、pszMainInstruction および pszWindowTitle パラメーターが指す文字列をリソース ファイルから取得しないでください。
ダイアログ ボックスが存在する状態でタスク ダイアログを作成する場合は、そのダイアログ ボックスへのハンドルを hWndParent パラメーターとして使用します。hWndParent パラメーターには、ダイアログ ボックス内のコントロールなどの子ウィンドウを指定しないでください。
タスク ダイアログ ボックスは正しいシステム定義の UI 要素を使用するため、MessageBox 関数で作成するメッセージ ボックスの代わりに使用してください。より多くの機能を実現するには、TaskDialogIndirect を使用してください。
次のサンプル コードは、より大きなプログラムの一部として含めるもので、タスク ダイアログを作成して入力をキャプチャする方法を示しています。
int nButtonPressed = 0;
TaskDialog(NULL, hInst,
MAKEINTRESOURCE(IDS_APPLICATION_TITLE),
MAKEINTRESOURCE(IDS_DOSOMETHING),
MAKEINTRESOURCE(IDS_SOMECONTENT),
TDCBF_OK_BUTTON | TDCBF_CANCEL_BUTTON,
TD_WARNING_ICON,
&nButtonPressed);
if (IDOK == nButtonPressed)
{
// OK button pressed
}
else if (IDCANCEL == nButtonPressed)
{
// Cancel pressed
}
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// COMCTL32.dll
#include <windows.h>
HRESULT TaskDialog(
HWND hwndOwner, // optional
HINSTANCE hInstance, // optional
LPCWSTR pszWindowTitle, // optional
LPCWSTR pszMainInstruction, // optional
LPCWSTR pszContent, // optional
TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons,
LPCWSTR pszIcon, // optional
INT* pnButton // optional
);[DllImport("COMCTL32.dll", ExactSpelling = true)]
static extern int TaskDialog(
IntPtr hwndOwner, // HWND optional
IntPtr hInstance, // HINSTANCE optional
[MarshalAs(UnmanagedType.LPWStr)] string pszWindowTitle, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pszMainInstruction, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pszContent, // LPCWSTR optional
int dwCommonButtons, // TASKDIALOG_COMMON_BUTTON_FLAGS
[MarshalAs(UnmanagedType.LPWStr)] string pszIcon, // LPCWSTR optional
IntPtr pnButton // INT* optional, out
);<DllImport("COMCTL32.dll", ExactSpelling:=True)>
Public Shared Function TaskDialog(
hwndOwner As IntPtr, ' HWND optional
hInstance As IntPtr, ' HINSTANCE optional
<MarshalAs(UnmanagedType.LPWStr)> pszWindowTitle As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pszMainInstruction As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pszContent As String, ' LPCWSTR optional
dwCommonButtons As Integer, ' TASKDIALOG_COMMON_BUTTON_FLAGS
<MarshalAs(UnmanagedType.LPWStr)> pszIcon As String, ' LPCWSTR optional
pnButton As IntPtr ' INT* optional, out
) As Integer
End Function' hwndOwner : HWND optional
' hInstance : HINSTANCE optional
' pszWindowTitle : LPCWSTR optional
' pszMainInstruction : LPCWSTR optional
' pszContent : LPCWSTR optional
' dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS
' pszIcon : LPCWSTR optional
' pnButton : INT* optional, out
Declare PtrSafe Function TaskDialog Lib "comctl32" ( _
ByVal hwndOwner As LongPtr, _
ByVal hInstance As LongPtr, _
ByVal pszWindowTitle As LongPtr, _
ByVal pszMainInstruction As LongPtr, _
ByVal pszContent As LongPtr, _
ByVal dwCommonButtons As Long, _
ByVal pszIcon As LongPtr, _
ByVal pnButton As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
TaskDialog = ctypes.windll.comctl32.TaskDialog
TaskDialog.restype = ctypes.c_int
TaskDialog.argtypes = [
wintypes.HANDLE, # hwndOwner : HWND optional
wintypes.HANDLE, # hInstance : HINSTANCE optional
wintypes.LPCWSTR, # pszWindowTitle : LPCWSTR optional
wintypes.LPCWSTR, # pszMainInstruction : LPCWSTR optional
wintypes.LPCWSTR, # pszContent : LPCWSTR optional
ctypes.c_int, # dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS
wintypes.LPCWSTR, # pszIcon : LPCWSTR optional
ctypes.POINTER(ctypes.c_int), # pnButton : INT* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('COMCTL32.dll')
TaskDialog = Fiddle::Function.new(
lib['TaskDialog'],
[
Fiddle::TYPE_VOIDP, # hwndOwner : HWND optional
Fiddle::TYPE_VOIDP, # hInstance : HINSTANCE optional
Fiddle::TYPE_VOIDP, # pszWindowTitle : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pszMainInstruction : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pszContent : LPCWSTR optional
Fiddle::TYPE_INT, # dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS
Fiddle::TYPE_VOIDP, # pszIcon : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pnButton : INT* optional, out
],
Fiddle::TYPE_INT)#[link(name = "comctl32")]
extern "system" {
fn TaskDialog(
hwndOwner: *mut core::ffi::c_void, // HWND optional
hInstance: *mut core::ffi::c_void, // HINSTANCE optional
pszWindowTitle: *const u16, // LPCWSTR optional
pszMainInstruction: *const u16, // LPCWSTR optional
pszContent: *const u16, // LPCWSTR optional
dwCommonButtons: i32, // TASKDIALOG_COMMON_BUTTON_FLAGS
pszIcon: *const u16, // LPCWSTR optional
pnButton: *mut i32 // INT* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("COMCTL32.dll")]
public static extern int TaskDialog(IntPtr hwndOwner, IntPtr hInstance, [MarshalAs(UnmanagedType.LPWStr)] string pszWindowTitle, [MarshalAs(UnmanagedType.LPWStr)] string pszMainInstruction, [MarshalAs(UnmanagedType.LPWStr)] string pszContent, int dwCommonButtons, [MarshalAs(UnmanagedType.LPWStr)] string pszIcon, IntPtr pnButton);
"@
$api = Add-Type -MemberDefinition $sig -Name 'COMCTL32_TaskDialog' -Namespace Win32 -PassThru
# $api::TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton)#uselib "COMCTL32.dll"
#func global TaskDialog "TaskDialog" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; TaskDialog hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, varptr(pnButton) ; 戻り値は stat
; hwndOwner : HWND optional -> "sptr"
; hInstance : HINSTANCE optional -> "sptr"
; pszWindowTitle : LPCWSTR optional -> "sptr"
; pszMainInstruction : LPCWSTR optional -> "sptr"
; pszContent : LPCWSTR optional -> "sptr"
; dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> "sptr"
; pszIcon : LPCWSTR optional -> "sptr"
; pnButton : INT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "COMCTL32.dll" #cfunc global TaskDialog "TaskDialog" sptr, sptr, wstr, wstr, wstr, int, wstr, var ; res = TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton) ; hwndOwner : HWND optional -> "sptr" ; hInstance : HINSTANCE optional -> "sptr" ; pszWindowTitle : LPCWSTR optional -> "wstr" ; pszMainInstruction : LPCWSTR optional -> "wstr" ; pszContent : LPCWSTR optional -> "wstr" ; dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> "int" ; pszIcon : LPCWSTR optional -> "wstr" ; pnButton : INT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "COMCTL32.dll" #cfunc global TaskDialog "TaskDialog" sptr, sptr, wstr, wstr, wstr, int, wstr, sptr ; res = TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, varptr(pnButton)) ; hwndOwner : HWND optional -> "sptr" ; hInstance : HINSTANCE optional -> "sptr" ; pszWindowTitle : LPCWSTR optional -> "wstr" ; pszMainInstruction : LPCWSTR optional -> "wstr" ; pszContent : LPCWSTR optional -> "wstr" ; dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> "int" ; pszIcon : LPCWSTR optional -> "wstr" ; pnButton : INT* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; HRESULT TaskDialog(HWND hwndOwner, HINSTANCE hInstance, LPCWSTR pszWindowTitle, LPCWSTR pszMainInstruction, LPCWSTR pszContent, TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons, LPCWSTR pszIcon, INT* pnButton) #uselib "COMCTL32.dll" #cfunc global TaskDialog "TaskDialog" intptr, intptr, wstr, wstr, wstr, int, wstr, var ; res = TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton) ; hwndOwner : HWND optional -> "intptr" ; hInstance : HINSTANCE optional -> "intptr" ; pszWindowTitle : LPCWSTR optional -> "wstr" ; pszMainInstruction : LPCWSTR optional -> "wstr" ; pszContent : LPCWSTR optional -> "wstr" ; dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> "int" ; pszIcon : LPCWSTR optional -> "wstr" ; pnButton : INT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT TaskDialog(HWND hwndOwner, HINSTANCE hInstance, LPCWSTR pszWindowTitle, LPCWSTR pszMainInstruction, LPCWSTR pszContent, TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons, LPCWSTR pszIcon, INT* pnButton) #uselib "COMCTL32.dll" #cfunc global TaskDialog "TaskDialog" intptr, intptr, wstr, wstr, wstr, int, wstr, intptr ; res = TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, varptr(pnButton)) ; hwndOwner : HWND optional -> "intptr" ; hInstance : HINSTANCE optional -> "intptr" ; pszWindowTitle : LPCWSTR optional -> "wstr" ; pszMainInstruction : LPCWSTR optional -> "wstr" ; pszContent : LPCWSTR optional -> "wstr" ; dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> "int" ; pszIcon : LPCWSTR optional -> "wstr" ; pnButton : INT* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
comctl32 = windows.NewLazySystemDLL("COMCTL32.dll")
procTaskDialog = comctl32.NewProc("TaskDialog")
)
// hwndOwner (HWND optional), hInstance (HINSTANCE optional), pszWindowTitle (LPCWSTR optional), pszMainInstruction (LPCWSTR optional), pszContent (LPCWSTR optional), dwCommonButtons (TASKDIALOG_COMMON_BUTTON_FLAGS), pszIcon (LPCWSTR optional), pnButton (INT* optional, out)
r1, _, err := procTaskDialog.Call(
uintptr(hwndOwner),
uintptr(hInstance),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszWindowTitle))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszMainInstruction))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszContent))),
uintptr(dwCommonButtons),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszIcon))),
uintptr(pnButton),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction TaskDialog(
hwndOwner: THandle; // HWND optional
hInstance: THandle; // HINSTANCE optional
pszWindowTitle: PWideChar; // LPCWSTR optional
pszMainInstruction: PWideChar; // LPCWSTR optional
pszContent: PWideChar; // LPCWSTR optional
dwCommonButtons: Integer; // TASKDIALOG_COMMON_BUTTON_FLAGS
pszIcon: PWideChar; // LPCWSTR optional
pnButton: Pointer // INT* optional, out
): Integer; stdcall;
external 'COMCTL32.dll' name 'TaskDialog';result := DllCall("COMCTL32\TaskDialog"
, "Ptr", hwndOwner ; HWND optional
, "Ptr", hInstance ; HINSTANCE optional
, "WStr", pszWindowTitle ; LPCWSTR optional
, "WStr", pszMainInstruction ; LPCWSTR optional
, "WStr", pszContent ; LPCWSTR optional
, "Int", dwCommonButtons ; TASKDIALOG_COMMON_BUTTON_FLAGS
, "WStr", pszIcon ; LPCWSTR optional
, "Ptr", pnButton ; INT* optional, out
, "Int") ; return: HRESULT●TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton) = DLL("COMCTL32.dll", "int TaskDialog(void*, void*, char*, char*, char*, int, char*, void*)")
# 呼び出し: TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton)
# hwndOwner : HWND optional -> "void*"
# hInstance : HINSTANCE optional -> "void*"
# pszWindowTitle : LPCWSTR optional -> "char*"
# pszMainInstruction : LPCWSTR optional -> "char*"
# pszContent : LPCWSTR optional -> "char*"
# dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> "int"
# pszIcon : LPCWSTR optional -> "char*"
# pnButton : INT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "comctl32" fn TaskDialog(
hwndOwner: ?*anyopaque, // HWND optional
hInstance: ?*anyopaque, // HINSTANCE optional
pszWindowTitle: [*c]const u16, // LPCWSTR optional
pszMainInstruction: [*c]const u16, // LPCWSTR optional
pszContent: [*c]const u16, // LPCWSTR optional
dwCommonButtons: i32, // TASKDIALOG_COMMON_BUTTON_FLAGS
pszIcon: [*c]const u16, // LPCWSTR optional
pnButton: [*c]i32 // INT* optional, out
) callconv(std.os.windows.WINAPI) i32;proc TaskDialog(
hwndOwner: pointer, # HWND optional
hInstance: pointer, # HINSTANCE optional
pszWindowTitle: WideCString, # LPCWSTR optional
pszMainInstruction: WideCString, # LPCWSTR optional
pszContent: WideCString, # LPCWSTR optional
dwCommonButtons: int32, # TASKDIALOG_COMMON_BUTTON_FLAGS
pszIcon: WideCString, # LPCWSTR optional
pnButton: ptr int32 # INT* optional, out
): int32 {.importc: "TaskDialog", stdcall, dynlib: "COMCTL32.dll".}pragma(lib, "comctl32");
extern(Windows)
int TaskDialog(
void* hwndOwner, // HWND optional
void* hInstance, // HINSTANCE optional
const(wchar)* pszWindowTitle, // LPCWSTR optional
const(wchar)* pszMainInstruction, // LPCWSTR optional
const(wchar)* pszContent, // LPCWSTR optional
int dwCommonButtons, // TASKDIALOG_COMMON_BUTTON_FLAGS
const(wchar)* pszIcon, // LPCWSTR optional
int* pnButton // INT* optional, out
);ccall((:TaskDialog, "COMCTL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Cwstring, Cwstring, Cwstring, Int32, Cwstring, Ptr{Int32}),
hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton)
# hwndOwner : HWND optional -> Ptr{Cvoid}
# hInstance : HINSTANCE optional -> Ptr{Cvoid}
# pszWindowTitle : LPCWSTR optional -> Cwstring
# pszMainInstruction : LPCWSTR optional -> Cwstring
# pszContent : LPCWSTR optional -> Cwstring
# dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> Int32
# pszIcon : LPCWSTR optional -> Cwstring
# pnButton : INT* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t TaskDialog(
void* hwndOwner,
void* hInstance,
const uint16_t* pszWindowTitle,
const uint16_t* pszMainInstruction,
const uint16_t* pszContent,
int32_t dwCommonButtons,
const uint16_t* pszIcon,
int32_t* pnButton);
]]
local comctl32 = ffi.load("comctl32")
-- comctl32.TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton)
-- hwndOwner : HWND optional
-- hInstance : HINSTANCE optional
-- pszWindowTitle : LPCWSTR optional
-- pszMainInstruction : LPCWSTR optional
-- pszContent : LPCWSTR optional
-- dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS
-- pszIcon : LPCWSTR optional
-- pnButton : INT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('COMCTL32.dll');
const TaskDialog = lib.func('__stdcall', 'TaskDialog', 'int32_t', ['void *', 'void *', 'str16', 'str16', 'str16', 'int32_t', 'str16', 'int32_t *']);
// TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton)
// hwndOwner : HWND optional -> 'void *'
// hInstance : HINSTANCE optional -> 'void *'
// pszWindowTitle : LPCWSTR optional -> 'str16'
// pszMainInstruction : LPCWSTR optional -> 'str16'
// pszContent : LPCWSTR optional -> 'str16'
// dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> 'int32_t'
// pszIcon : LPCWSTR optional -> 'str16'
// pnButton : INT* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("COMCTL32.dll", {
TaskDialog: { parameters: ["pointer", "pointer", "buffer", "buffer", "buffer", "i32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton)
// hwndOwner : HWND optional -> "pointer"
// hInstance : HINSTANCE optional -> "pointer"
// pszWindowTitle : LPCWSTR optional -> "buffer"
// pszMainInstruction : LPCWSTR optional -> "buffer"
// pszContent : LPCWSTR optional -> "buffer"
// dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> "i32"
// pszIcon : LPCWSTR optional -> "buffer"
// pnButton : INT* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t TaskDialog(
void* hwndOwner,
void* hInstance,
const uint16_t* pszWindowTitle,
const uint16_t* pszMainInstruction,
const uint16_t* pszContent,
int32_t dwCommonButtons,
const uint16_t* pszIcon,
int32_t* pnButton);
C, "COMCTL32.dll");
// $ffi->TaskDialog(hwndOwner, hInstance, pszWindowTitle, pszMainInstruction, pszContent, dwCommonButtons, pszIcon, pnButton);
// hwndOwner : HWND optional
// hInstance : HINSTANCE optional
// pszWindowTitle : LPCWSTR optional
// pszMainInstruction : LPCWSTR optional
// pszContent : LPCWSTR optional
// dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS
// pszIcon : LPCWSTR optional
// pnButton : INT* optional, 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 Comctl32 extends StdCallLibrary {
Comctl32 INSTANCE = Native.load("comctl32", Comctl32.class);
int TaskDialog(
Pointer hwndOwner, // HWND optional
Pointer hInstance, // HINSTANCE optional
WString pszWindowTitle, // LPCWSTR optional
WString pszMainInstruction, // LPCWSTR optional
WString pszContent, // LPCWSTR optional
int dwCommonButtons, // TASKDIALOG_COMMON_BUTTON_FLAGS
WString pszIcon, // LPCWSTR optional
IntByReference pnButton // INT* optional, out
);
}@[Link("comctl32")]
lib LibCOMCTL32
fun TaskDialog = TaskDialog(
hwndOwner : Void*, # HWND optional
hInstance : Void*, # HINSTANCE optional
pszWindowTitle : UInt16*, # LPCWSTR optional
pszMainInstruction : UInt16*, # LPCWSTR optional
pszContent : UInt16*, # LPCWSTR optional
dwCommonButtons : Int32, # TASKDIALOG_COMMON_BUTTON_FLAGS
pszIcon : UInt16*, # LPCWSTR optional
pnButton : Int32* # INT* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef TaskDialogNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Int32, Pointer<Utf16>, Pointer<Int32>);
typedef TaskDialogDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Int32>);
final TaskDialog = DynamicLibrary.open('COMCTL32.dll')
.lookupFunction<TaskDialogNative, TaskDialogDart>('TaskDialog');
// hwndOwner : HWND optional -> Pointer<Void>
// hInstance : HINSTANCE optional -> Pointer<Void>
// pszWindowTitle : LPCWSTR optional -> Pointer<Utf16>
// pszMainInstruction : LPCWSTR optional -> Pointer<Utf16>
// pszContent : LPCWSTR optional -> Pointer<Utf16>
// dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> Int32
// pszIcon : LPCWSTR optional -> Pointer<Utf16>
// pnButton : INT* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function TaskDialog(
hwndOwner: THandle; // HWND optional
hInstance: THandle; // HINSTANCE optional
pszWindowTitle: PWideChar; // LPCWSTR optional
pszMainInstruction: PWideChar; // LPCWSTR optional
pszContent: PWideChar; // LPCWSTR optional
dwCommonButtons: Integer; // TASKDIALOG_COMMON_BUTTON_FLAGS
pszIcon: PWideChar; // LPCWSTR optional
pnButton: Pointer // INT* optional, out
): Integer; stdcall;
external 'COMCTL32.dll' name 'TaskDialog';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "TaskDialog"
c_TaskDialog :: Ptr () -> Ptr () -> CWString -> CWString -> CWString -> Int32 -> CWString -> Ptr Int32 -> IO Int32
-- hwndOwner : HWND optional -> Ptr ()
-- hInstance : HINSTANCE optional -> Ptr ()
-- pszWindowTitle : LPCWSTR optional -> CWString
-- pszMainInstruction : LPCWSTR optional -> CWString
-- pszContent : LPCWSTR optional -> CWString
-- dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> Int32
-- pszIcon : LPCWSTR optional -> CWString
-- pnButton : INT* optional, out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let taskdialog =
foreign "TaskDialog"
((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> (ptr int32_t) @-> returning int32_t)
(* hwndOwner : HWND optional -> (ptr void) *)
(* hInstance : HINSTANCE optional -> (ptr void) *)
(* pszWindowTitle : LPCWSTR optional -> (ptr uint16_t) *)
(* pszMainInstruction : LPCWSTR optional -> (ptr uint16_t) *)
(* pszContent : LPCWSTR optional -> (ptr uint16_t) *)
(* dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> int32_t *)
(* pszIcon : LPCWSTR optional -> (ptr uint16_t) *)
(* pnButton : INT* optional, out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library comctl32 (t "COMCTL32.dll"))
(cffi:use-foreign-library comctl32)
(cffi:defcfun ("TaskDialog" task-dialog :convention :stdcall) :int32
(hwnd-owner :pointer) ; HWND optional
(h-instance :pointer) ; HINSTANCE optional
(psz-window-title (:string :encoding :utf-16le)) ; LPCWSTR optional
(psz-main-instruction (:string :encoding :utf-16le)) ; LPCWSTR optional
(psz-content (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-common-buttons :int32) ; TASKDIALOG_COMMON_BUTTON_FLAGS
(psz-icon (:string :encoding :utf-16le)) ; LPCWSTR optional
(pn-button :pointer)) ; INT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $TaskDialog = Win32::API::More->new('COMCTL32',
'int TaskDialog(HANDLE hwndOwner, HANDLE hInstance, LPCWSTR pszWindowTitle, LPCWSTR pszMainInstruction, LPCWSTR pszContent, int dwCommonButtons, LPCWSTR pszIcon, LPVOID pnButton)');
# my $ret = $TaskDialog->Call($hwndOwner, $hInstance, $pszWindowTitle, $pszMainInstruction, $pszContent, $dwCommonButtons, $pszIcon, $pnButton);
# hwndOwner : HWND optional -> HANDLE
# hInstance : HINSTANCE optional -> HANDLE
# pszWindowTitle : LPCWSTR optional -> LPCWSTR
# pszMainInstruction : LPCWSTR optional -> LPCWSTR
# pszContent : LPCWSTR optional -> LPCWSTR
# dwCommonButtons : TASKDIALOG_COMMON_BUTTON_FLAGS -> int
# pszIcon : LPCWSTR optional -> LPCWSTR
# pnButton : INT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。