Win32 API 日本語リファレンス
ホームSystem.Console › AllocConsoleWithOptions

AllocConsoleWithOptions

関数
オプションを指定して呼び出し元プロセスにコンソールを割り当てる。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

HRESULT AllocConsoleWithOptions(
    ALLOC_CONSOLE_OPTIONS* options,   // optional
    ALLOC_CONSOLE_RESULT* result   // optional
);

パラメーター

名前方向
optionsALLOC_CONSOLE_OPTIONS*inoptional
resultALLOC_CONSOLE_RESULT*outoptional

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT AllocConsoleWithOptions(
    ALLOC_CONSOLE_OPTIONS* options,   // optional
    ALLOC_CONSOLE_RESULT* result   // optional
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern int AllocConsoleWithOptions(
    IntPtr options,   // ALLOC_CONSOLE_OPTIONS* optional
    IntPtr result   // ALLOC_CONSOLE_RESULT* optional, out
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function AllocConsoleWithOptions(
    options As IntPtr,   ' ALLOC_CONSOLE_OPTIONS* optional
    result As IntPtr   ' ALLOC_CONSOLE_RESULT* optional, out
) As Integer
End Function
' options : ALLOC_CONSOLE_OPTIONS* optional
' result : ALLOC_CONSOLE_RESULT* optional, out
Declare PtrSafe Function AllocConsoleWithOptions Lib "kernel32" ( _
    ByVal options As LongPtr, _
    ByVal result As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

AllocConsoleWithOptions = ctypes.windll.kernel32.AllocConsoleWithOptions
AllocConsoleWithOptions.restype = ctypes.c_int
AllocConsoleWithOptions.argtypes = [
    ctypes.c_void_p,  # options : ALLOC_CONSOLE_OPTIONS* optional
    ctypes.c_void_p,  # result : ALLOC_CONSOLE_RESULT* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
AllocConsoleWithOptions = Fiddle::Function.new(
  lib['AllocConsoleWithOptions'],
  [
    Fiddle::TYPE_VOIDP,  # options : ALLOC_CONSOLE_OPTIONS* optional
    Fiddle::TYPE_VOIDP,  # result : ALLOC_CONSOLE_RESULT* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn AllocConsoleWithOptions(
        options: *mut ALLOC_CONSOLE_OPTIONS,  // ALLOC_CONSOLE_OPTIONS* optional
        result: *mut i32  // ALLOC_CONSOLE_RESULT* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern int AllocConsoleWithOptions(IntPtr options, IntPtr result);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_AllocConsoleWithOptions' -Namespace Win32 -PassThru
# $api::AllocConsoleWithOptions(options, result)
#uselib "KERNEL32.dll"
#func global AllocConsoleWithOptions "AllocConsoleWithOptions" sptr, sptr
; AllocConsoleWithOptions varptr(options), result   ; 戻り値は stat
; options : ALLOC_CONSOLE_OPTIONS* optional -> "sptr"
; result : ALLOC_CONSOLE_RESULT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global AllocConsoleWithOptions "AllocConsoleWithOptions" var, int
; res = AllocConsoleWithOptions(options, result)
; options : ALLOC_CONSOLE_OPTIONS* optional -> "var"
; result : ALLOC_CONSOLE_RESULT* optional, out -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT AllocConsoleWithOptions(ALLOC_CONSOLE_OPTIONS* options, ALLOC_CONSOLE_RESULT* result)
#uselib "KERNEL32.dll"
#cfunc global AllocConsoleWithOptions "AllocConsoleWithOptions" var, int
; res = AllocConsoleWithOptions(options, result)
; options : ALLOC_CONSOLE_OPTIONS* optional -> "var"
; result : ALLOC_CONSOLE_RESULT* optional, out -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procAllocConsoleWithOptions = kernel32.NewProc("AllocConsoleWithOptions")
)

// options (ALLOC_CONSOLE_OPTIONS* optional), result (ALLOC_CONSOLE_RESULT* optional, out)
r1, _, err := procAllocConsoleWithOptions.Call(
	uintptr(options),
	uintptr(result),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function AllocConsoleWithOptions(
  options: Pointer;   // ALLOC_CONSOLE_OPTIONS* optional
  result: Pointer   // ALLOC_CONSOLE_RESULT* optional, out
): Integer; stdcall;
  external 'KERNEL32.dll' name 'AllocConsoleWithOptions';
result := DllCall("KERNEL32\AllocConsoleWithOptions"
    , "Ptr", options   ; ALLOC_CONSOLE_OPTIONS* optional
    , "Ptr", result   ; ALLOC_CONSOLE_RESULT* optional, out
    , "Int")   ; return: HRESULT
●AllocConsoleWithOptions(options, result) = DLL("KERNEL32.dll", "int AllocConsoleWithOptions(void*, void*)")
# 呼び出し: AllocConsoleWithOptions(options, result)
# options : ALLOC_CONSOLE_OPTIONS* optional -> "void*"
# result : ALLOC_CONSOLE_RESULT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。