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

SetConsoleOutputCP

関数
コンソールの出力コードページを設定する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり

シグネチャ

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

BOOL SetConsoleOutputCP(
    DWORD wCodePageID
);

パラメーター

名前方向
wCodePageIDDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetConsoleOutputCP(
    DWORD wCodePageID
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetConsoleOutputCP(
    uint wCodePageID   // DWORD
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetConsoleOutputCP(
    wCodePageID As UInteger   ' DWORD
) As Boolean
End Function
' wCodePageID : DWORD
Declare PtrSafe Function SetConsoleOutputCP Lib "kernel32" ( _
    ByVal wCodePageID As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetConsoleOutputCP = ctypes.windll.kernel32.SetConsoleOutputCP
SetConsoleOutputCP.restype = wintypes.BOOL
SetConsoleOutputCP.argtypes = [
    wintypes.DWORD,  # wCodePageID : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetConsoleOutputCP = Fiddle::Function.new(
  lib['SetConsoleOutputCP'],
  [
    -Fiddle::TYPE_INT,  # wCodePageID : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SetConsoleOutputCP(
        wCodePageID: u32  // DWORD
    ) -> 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 SetConsoleOutputCP(uint wCodePageID);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetConsoleOutputCP' -Namespace Win32 -PassThru
# $api::SetConsoleOutputCP(wCodePageID)
#uselib "KERNEL32.dll"
#func global SetConsoleOutputCP "SetConsoleOutputCP" sptr
; SetConsoleOutputCP wCodePageID   ; 戻り値は stat
; wCodePageID : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetConsoleOutputCP "SetConsoleOutputCP" int
; res = SetConsoleOutputCP(wCodePageID)
; wCodePageID : DWORD -> "int"
; BOOL SetConsoleOutputCP(DWORD wCodePageID)
#uselib "KERNEL32.dll"
#cfunc global SetConsoleOutputCP "SetConsoleOutputCP" int
; res = SetConsoleOutputCP(wCodePageID)
; wCodePageID : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetConsoleOutputCP = kernel32.NewProc("SetConsoleOutputCP")
)

// wCodePageID (DWORD)
r1, _, err := procSetConsoleOutputCP.Call(
	uintptr(wCodePageID),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetConsoleOutputCP(
  wCodePageID: DWORD   // DWORD
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetConsoleOutputCP';
result := DllCall("KERNEL32\SetConsoleOutputCP"
    , "UInt", wCodePageID   ; DWORD
    , "Int")   ; return: BOOL
●SetConsoleOutputCP(wCodePageID) = DLL("KERNEL32.dll", "bool SetConsoleOutputCP(dword)")
# 呼び出し: SetConsoleOutputCP(wCodePageID)
# wCodePageID : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。