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新規コンソール割り当ての挙動を指定するALLOC_CONSOLE_OPTIONS構造体へのポインタ。NULL可。
resultALLOC_CONSOLE_RESULT*outoptional割り当て結果を受け取るALLOC_CONSOLE_RESULT構造体へのポインタ。

戻り値の型: 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), varptr(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, var
; res = AllocConsoleWithOptions(options, result)
; options : ALLOC_CONSOLE_OPTIONS* optional -> "var"
; result : ALLOC_CONSOLE_RESULT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT AllocConsoleWithOptions(ALLOC_CONSOLE_OPTIONS* options, ALLOC_CONSOLE_RESULT* result)
#uselib "KERNEL32.dll"
#cfunc global AllocConsoleWithOptions "AllocConsoleWithOptions" var, var
; res = AllocConsoleWithOptions(options, result)
; options : ALLOC_CONSOLE_OPTIONS* optional -> "var"
; result : ALLOC_CONSOLE_RESULT* optional, out -> "var"
; ※出力/バッファ引数は 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)。
const std = @import("std");

extern "kernel32" fn AllocConsoleWithOptions(
    options: [*c]ALLOC_CONSOLE_OPTIONS, // ALLOC_CONSOLE_OPTIONS* optional
    result: [*c]i32 // ALLOC_CONSOLE_RESULT* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc AllocConsoleWithOptions(
    options: ptr ALLOC_CONSOLE_OPTIONS,  # ALLOC_CONSOLE_OPTIONS* optional
    result: ptr int32  # ALLOC_CONSOLE_RESULT* optional, out
): int32 {.importc: "AllocConsoleWithOptions", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int AllocConsoleWithOptions(
    ALLOC_CONSOLE_OPTIONS* options,   // ALLOC_CONSOLE_OPTIONS* optional
    int* result   // ALLOC_CONSOLE_RESULT* optional, out
);
ccall((:AllocConsoleWithOptions, "KERNEL32.dll"), stdcall, Int32,
      (Ptr{ALLOC_CONSOLE_OPTIONS}, Ptr{Int32}),
      options, result)
# options : ALLOC_CONSOLE_OPTIONS* optional -> Ptr{ALLOC_CONSOLE_OPTIONS}
# result : ALLOC_CONSOLE_RESULT* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t AllocConsoleWithOptions(
    void* options,
    int32_t* result);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.AllocConsoleWithOptions(options, result)
-- options : ALLOC_CONSOLE_OPTIONS* optional
-- result : ALLOC_CONSOLE_RESULT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const AllocConsoleWithOptions = lib.func('__stdcall', 'AllocConsoleWithOptions', 'int32_t', ['void *', 'int32_t *']);
// AllocConsoleWithOptions(options, result)
// options : ALLOC_CONSOLE_OPTIONS* optional -> 'void *'
// result : ALLOC_CONSOLE_RESULT* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  AllocConsoleWithOptions: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.AllocConsoleWithOptions(options, result)
// options : ALLOC_CONSOLE_OPTIONS* optional -> "pointer"
// result : ALLOC_CONSOLE_RESULT* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t AllocConsoleWithOptions(
    void* options,
    int32_t* result);
C, "KERNEL32.dll");
// $ffi->AllocConsoleWithOptions(options, result);
// options : ALLOC_CONSOLE_OPTIONS* optional
// result : ALLOC_CONSOLE_RESULT* 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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    int AllocConsoleWithOptions(
        Pointer options,   // ALLOC_CONSOLE_OPTIONS* optional
        IntByReference result   // ALLOC_CONSOLE_RESULT* optional, out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun AllocConsoleWithOptions = AllocConsoleWithOptions(
    options : ALLOC_CONSOLE_OPTIONS*,   # ALLOC_CONSOLE_OPTIONS* optional
    result : Int32*   # ALLOC_CONSOLE_RESULT* 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 AllocConsoleWithOptionsNative = Int32 Function(Pointer<Void>, Pointer<Int32>);
typedef AllocConsoleWithOptionsDart = int Function(Pointer<Void>, Pointer<Int32>);
final AllocConsoleWithOptions = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<AllocConsoleWithOptionsNative, AllocConsoleWithOptionsDart>('AllocConsoleWithOptions');
// options : ALLOC_CONSOLE_OPTIONS* optional -> Pointer<Void>
// result : ALLOC_CONSOLE_RESULT* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function AllocConsoleWithOptions(
  options: Pointer;   // ALLOC_CONSOLE_OPTIONS* optional
  result: Pointer   // ALLOC_CONSOLE_RESULT* optional, out
): Integer; stdcall;
  external 'KERNEL32.dll' name 'AllocConsoleWithOptions';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "AllocConsoleWithOptions"
  c_AllocConsoleWithOptions :: Ptr () -> Ptr Int32 -> IO Int32
-- options : ALLOC_CONSOLE_OPTIONS* optional -> Ptr ()
-- result : ALLOC_CONSOLE_RESULT* optional, out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let allocconsolewithoptions =
  foreign "AllocConsoleWithOptions"
    ((ptr void) @-> (ptr int32_t) @-> returning int32_t)
(* options : ALLOC_CONSOLE_OPTIONS* optional -> (ptr void) *)
(* result : ALLOC_CONSOLE_RESULT* optional, out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("AllocConsoleWithOptions" alloc-console-with-options :convention :stdcall) :int32
  (options :pointer)   ; ALLOC_CONSOLE_OPTIONS* optional
  (result :pointer))   ; ALLOC_CONSOLE_RESULT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $AllocConsoleWithOptions = Win32::API::More->new('KERNEL32',
    'int AllocConsoleWithOptions(LPVOID options, LPVOID result)');
# my $ret = $AllocConsoleWithOptions->Call($options, $result);
# options : ALLOC_CONSOLE_OPTIONS* optional -> LPVOID
# result : ALLOC_CONSOLE_RESULT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型