Win32 API 日本語リファレンス
ホームUI.WindowsAndMessaging › DialogBoxParamA

DialogBoxParamA

関数
モーダルダイアログを生成し終了まで実行する(ANSI)。
DLLUSER32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (ANSI / -A)
#include <windows.h>

INT_PTR DialogBoxParamA(
    HINSTANCE hInstance,   // optional
    LPCSTR lpTemplateName,
    HWND hWndParent,   // optional
    DLGPROC lpDialogFunc,   // optional
    LPARAM dwInitParam
);

パラメーター

名前方向
hInstanceHINSTANCEinoptional
lpTemplateNameLPCSTRin
hWndParentHWNDinoptional
lpDialogFuncDLGPROCinoptional
dwInitParamLPARAMin

戻り値の型: INT_PTR

各言語での呼び出し定義

// USER32.dll  (ANSI / -A)
#include <windows.h>

INT_PTR DialogBoxParamA(
    HINSTANCE hInstance,   // optional
    LPCSTR lpTemplateName,
    HWND hWndParent,   // optional
    DLGPROC lpDialogFunc,   // optional
    LPARAM dwInitParam
);
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr DialogBoxParamA(
    IntPtr hInstance,   // HINSTANCE optional
    [MarshalAs(UnmanagedType.LPStr)] string lpTemplateName,   // LPCSTR
    IntPtr hWndParent,   // HWND optional
    IntPtr lpDialogFunc,   // DLGPROC optional
    IntPtr dwInitParam   // LPARAM
);
<DllImport("USER32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DialogBoxParamA(
    hInstance As IntPtr,   ' HINSTANCE optional
    <MarshalAs(UnmanagedType.LPStr)> lpTemplateName As String,   ' LPCSTR
    hWndParent As IntPtr,   ' HWND optional
    lpDialogFunc As IntPtr,   ' DLGPROC optional
    dwInitParam As IntPtr   ' LPARAM
) As IntPtr
End Function
' hInstance : HINSTANCE optional
' lpTemplateName : LPCSTR
' hWndParent : HWND optional
' lpDialogFunc : DLGPROC optional
' dwInitParam : LPARAM
Declare PtrSafe Function DialogBoxParamA Lib "user32" ( _
    ByVal hInstance As LongPtr, _
    ByVal lpTemplateName As String, _
    ByVal hWndParent As LongPtr, _
    ByVal lpDialogFunc As LongPtr, _
    ByVal dwInitParam As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DialogBoxParamA = ctypes.windll.user32.DialogBoxParamA
DialogBoxParamA.restype = ctypes.c_ssize_t
DialogBoxParamA.argtypes = [
    wintypes.HANDLE,  # hInstance : HINSTANCE optional
    wintypes.LPCSTR,  # lpTemplateName : LPCSTR
    wintypes.HANDLE,  # hWndParent : HWND optional
    ctypes.c_void_p,  # lpDialogFunc : DLGPROC optional
    ctypes.c_ssize_t,  # dwInitParam : LPARAM
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
DialogBoxParamA = Fiddle::Function.new(
  lib['DialogBoxParamA'],
  [
    Fiddle::TYPE_VOIDP,  # hInstance : HINSTANCE optional
    Fiddle::TYPE_VOIDP,  # lpTemplateName : LPCSTR
    Fiddle::TYPE_VOIDP,  # hWndParent : HWND optional
    Fiddle::TYPE_VOIDP,  # lpDialogFunc : DLGPROC optional
    Fiddle::TYPE_INTPTR_T,  # dwInitParam : LPARAM
  ],
  Fiddle::TYPE_INTPTR_T)
#[link(name = "user32")]
extern "system" {
    fn DialogBoxParamA(
        hInstance: *mut core::ffi::c_void,  // HINSTANCE optional
        lpTemplateName: *const u8,  // LPCSTR
        hWndParent: *mut core::ffi::c_void,  // HWND optional
        lpDialogFunc: *const core::ffi::c_void,  // DLGPROC optional
        dwInitParam: isize  // LPARAM
    ) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern IntPtr DialogBoxParamA(IntPtr hInstance, [MarshalAs(UnmanagedType.LPStr)] string lpTemplateName, IntPtr hWndParent, IntPtr lpDialogFunc, IntPtr dwInitParam);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DialogBoxParamA' -Namespace Win32 -PassThru
# $api::DialogBoxParamA(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam)
#uselib "USER32.dll"
#func global DialogBoxParamA "DialogBoxParamA" sptr, sptr, sptr, sptr, sptr
; DialogBoxParamA hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam   ; 戻り値は stat
; hInstance : HINSTANCE optional -> "sptr"
; lpTemplateName : LPCSTR -> "sptr"
; hWndParent : HWND optional -> "sptr"
; lpDialogFunc : DLGPROC optional -> "sptr"
; dwInitParam : LPARAM -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global DialogBoxParamA "DialogBoxParamA" sptr, str, sptr, sptr, sptr
; res = DialogBoxParamA(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam)
; hInstance : HINSTANCE optional -> "sptr"
; lpTemplateName : LPCSTR -> "str"
; hWndParent : HWND optional -> "sptr"
; lpDialogFunc : DLGPROC optional -> "sptr"
; dwInitParam : LPARAM -> "sptr"
; INT_PTR DialogBoxParamA(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
#uselib "USER32.dll"
#cfunc global DialogBoxParamA "DialogBoxParamA" intptr, str, intptr, intptr, intptr
; res = DialogBoxParamA(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam)
; hInstance : HINSTANCE optional -> "intptr"
; lpTemplateName : LPCSTR -> "str"
; hWndParent : HWND optional -> "intptr"
; lpDialogFunc : DLGPROC optional -> "intptr"
; dwInitParam : LPARAM -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procDialogBoxParamA = user32.NewProc("DialogBoxParamA")
)

// hInstance (HINSTANCE optional), lpTemplateName (LPCSTR), hWndParent (HWND optional), lpDialogFunc (DLGPROC optional), dwInitParam (LPARAM)
r1, _, err := procDialogBoxParamA.Call(
	uintptr(hInstance),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpTemplateName))),
	uintptr(hWndParent),
	uintptr(lpDialogFunc),
	uintptr(dwInitParam),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT_PTR
function DialogBoxParamA(
  hInstance: THandle;   // HINSTANCE optional
  lpTemplateName: PAnsiChar;   // LPCSTR
  hWndParent: THandle;   // HWND optional
  lpDialogFunc: Pointer;   // DLGPROC optional
  dwInitParam: NativeInt   // LPARAM
): NativeInt; stdcall;
  external 'USER32.dll' name 'DialogBoxParamA';
result := DllCall("USER32\DialogBoxParamA"
    , "Ptr", hInstance   ; HINSTANCE optional
    , "AStr", lpTemplateName   ; LPCSTR
    , "Ptr", hWndParent   ; HWND optional
    , "Ptr", lpDialogFunc   ; DLGPROC optional
    , "Ptr", dwInitParam   ; LPARAM
    , "Ptr")   ; return: INT_PTR
●DialogBoxParamA(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam) = DLL("USER32.dll", "int DialogBoxParamA(void*, char*, void*, void*, int)")
# 呼び出し: DialogBoxParamA(hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam)
# hInstance : HINSTANCE optional -> "void*"
# lpTemplateName : LPCSTR -> "char*"
# hWndParent : HWND optional -> "void*"
# lpDialogFunc : DLGPROC optional -> "void*"
# dwInitParam : LPARAM -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。