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

FillConsoleOutputAttribute

関数
コンソール画面の指定位置から同じ文字属性を連続して設定する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり

シグネチャ

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

BOOL FillConsoleOutputAttribute(
    HANDLE hConsoleOutput,
    WORD wAttribute,
    DWORD nLength,
    COORD dwWriteCoord,
    DWORD* lpNumberOfAttrsWritten
);

パラメーター

名前方向
hConsoleOutputHANDLEin
wAttributeWORDin
nLengthDWORDin
dwWriteCoordCOORDin
lpNumberOfAttrsWrittenDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL FillConsoleOutputAttribute(
    HANDLE hConsoleOutput,
    WORD wAttribute,
    DWORD nLength,
    COORD dwWriteCoord,
    DWORD* lpNumberOfAttrsWritten
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool FillConsoleOutputAttribute(
    IntPtr hConsoleOutput,   // HANDLE
    ushort wAttribute,   // WORD
    uint nLength,   // DWORD
    COORD dwWriteCoord,   // COORD
    out uint lpNumberOfAttrsWritten   // DWORD* out
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FillConsoleOutputAttribute(
    hConsoleOutput As IntPtr,   ' HANDLE
    wAttribute As UShort,   ' WORD
    nLength As UInteger,   ' DWORD
    dwWriteCoord As COORD,   ' COORD
    <Out> ByRef lpNumberOfAttrsWritten As UInteger   ' DWORD* out
) As Boolean
End Function
' hConsoleOutput : HANDLE
' wAttribute : WORD
' nLength : DWORD
' dwWriteCoord : COORD
' lpNumberOfAttrsWritten : DWORD* out
Declare PtrSafe Function FillConsoleOutputAttribute Lib "kernel32" ( _
    ByVal hConsoleOutput As LongPtr, _
    ByVal wAttribute As Integer, _
    ByVal nLength As Long, _
    ByVal dwWriteCoord As LongPtr, _
    ByRef lpNumberOfAttrsWritten As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

FillConsoleOutputAttribute = ctypes.windll.kernel32.FillConsoleOutputAttribute
FillConsoleOutputAttribute.restype = wintypes.BOOL
FillConsoleOutputAttribute.argtypes = [
    wintypes.HANDLE,  # hConsoleOutput : HANDLE
    ctypes.c_ushort,  # wAttribute : WORD
    wintypes.DWORD,  # nLength : DWORD
    COORD,  # dwWriteCoord : COORD
    ctypes.POINTER(wintypes.DWORD),  # lpNumberOfAttrsWritten : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
FillConsoleOutputAttribute = Fiddle::Function.new(
  lib['FillConsoleOutputAttribute'],
  [
    Fiddle::TYPE_VOIDP,  # hConsoleOutput : HANDLE
    -Fiddle::TYPE_SHORT,  # wAttribute : WORD
    -Fiddle::TYPE_INT,  # nLength : DWORD
    Fiddle::TYPE_VOIDP,  # dwWriteCoord : COORD
    Fiddle::TYPE_VOIDP,  # lpNumberOfAttrsWritten : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn FillConsoleOutputAttribute(
        hConsoleOutput: *mut core::ffi::c_void,  // HANDLE
        wAttribute: u16,  // WORD
        nLength: u32,  // DWORD
        dwWriteCoord: COORD,  // COORD
        lpNumberOfAttrsWritten: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool FillConsoleOutputAttribute(IntPtr hConsoleOutput, ushort wAttribute, uint nLength, COORD dwWriteCoord, out uint lpNumberOfAttrsWritten);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_FillConsoleOutputAttribute' -Namespace Win32 -PassThru
# $api::FillConsoleOutputAttribute(hConsoleOutput, wAttribute, nLength, dwWriteCoord, lpNumberOfAttrsWritten)
#uselib "KERNEL32.dll"
#func global FillConsoleOutputAttribute "FillConsoleOutputAttribute" sptr, sptr, sptr, sptr, sptr
; FillConsoleOutputAttribute hConsoleOutput, wAttribute, nLength, dwWriteCoord, varptr(lpNumberOfAttrsWritten)   ; 戻り値は stat
; hConsoleOutput : HANDLE -> "sptr"
; wAttribute : WORD -> "sptr"
; nLength : DWORD -> "sptr"
; dwWriteCoord : COORD -> "sptr"
; lpNumberOfAttrsWritten : DWORD* out -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global FillConsoleOutputAttribute "FillConsoleOutputAttribute" sptr, int, int, int, var
; res = FillConsoleOutputAttribute(hConsoleOutput, wAttribute, nLength, dwWriteCoord, lpNumberOfAttrsWritten)
; hConsoleOutput : HANDLE -> "sptr"
; wAttribute : WORD -> "int"
; nLength : DWORD -> "int"
; dwWriteCoord : COORD -> "int"
; lpNumberOfAttrsWritten : DWORD* out -> "var"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL FillConsoleOutputAttribute(HANDLE hConsoleOutput, WORD wAttribute, DWORD nLength, COORD dwWriteCoord, DWORD* lpNumberOfAttrsWritten)
#uselib "KERNEL32.dll"
#cfunc global FillConsoleOutputAttribute "FillConsoleOutputAttribute" intptr, int, int, int, var
; res = FillConsoleOutputAttribute(hConsoleOutput, wAttribute, nLength, dwWriteCoord, lpNumberOfAttrsWritten)
; hConsoleOutput : HANDLE -> "intptr"
; wAttribute : WORD -> "int"
; nLength : DWORD -> "int"
; dwWriteCoord : COORD -> "int"
; lpNumberOfAttrsWritten : DWORD* out -> "var"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procFillConsoleOutputAttribute = kernel32.NewProc("FillConsoleOutputAttribute")
)

// hConsoleOutput (HANDLE), wAttribute (WORD), nLength (DWORD), dwWriteCoord (COORD), lpNumberOfAttrsWritten (DWORD* out)
r1, _, err := procFillConsoleOutputAttribute.Call(
	uintptr(hConsoleOutput),
	uintptr(wAttribute),
	uintptr(nLength),
	uintptr(dwWriteCoord),
	uintptr(lpNumberOfAttrsWritten),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function FillConsoleOutputAttribute(
  hConsoleOutput: THandle;   // HANDLE
  wAttribute: Word;   // WORD
  nLength: DWORD;   // DWORD
  dwWriteCoord: COORD;   // COORD
  lpNumberOfAttrsWritten: Pointer   // DWORD* out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'FillConsoleOutputAttribute';
result := DllCall("KERNEL32\FillConsoleOutputAttribute"
    , "Ptr", hConsoleOutput   ; HANDLE
    , "UShort", wAttribute   ; WORD
    , "UInt", nLength   ; DWORD
    , "Ptr", dwWriteCoord   ; COORD
    , "Ptr", lpNumberOfAttrsWritten   ; DWORD* out
    , "Int")   ; return: BOOL
●FillConsoleOutputAttribute(hConsoleOutput, wAttribute, nLength, dwWriteCoord, lpNumberOfAttrsWritten) = DLL("KERNEL32.dll", "bool FillConsoleOutputAttribute(void*, int, dword, void*, void*)")
# 呼び出し: FillConsoleOutputAttribute(hConsoleOutput, wAttribute, nLength, dwWriteCoord, lpNumberOfAttrsWritten)
# hConsoleOutput : HANDLE -> "void*"
# wAttribute : WORD -> "int"
# nLength : DWORD -> "dword"
# dwWriteCoord : COORD -> "void*"
# lpNumberOfAttrsWritten : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。