Win32 API 日本語リファレンス
ホームGlobalization › GetCPInfo

GetCPInfo

関数
指定コードページの情報を取得する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL GetCPInfo(
    DWORD CodePage,
    CPINFO* lpCPInfo
);

パラメーター

名前方向
CodePageDWORDin
lpCPInfoCPINFO*out

戻り値の型: BOOL

各言語での呼び出し定義

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

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

GetCPInfo = ctypes.windll.kernel32.GetCPInfo
GetCPInfo.restype = wintypes.BOOL
GetCPInfo.argtypes = [
    wintypes.DWORD,  # CodePage : DWORD
    ctypes.c_void_p,  # lpCPInfo : CPINFO* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetCPInfo = Fiddle::Function.new(
  lib['GetCPInfo'],
  [
    -Fiddle::TYPE_INT,  # CodePage : DWORD
    Fiddle::TYPE_VOIDP,  # lpCPInfo : CPINFO* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetCPInfo(
        CodePage: u32,  // DWORD
        lpCPInfo: *mut CPINFO  // CPINFO* 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 GetCPInfo(uint CodePage, IntPtr lpCPInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetCPInfo' -Namespace Win32 -PassThru
# $api::GetCPInfo(CodePage, lpCPInfo)
#uselib "KERNEL32.dll"
#func global GetCPInfo "GetCPInfo" sptr, sptr
; GetCPInfo CodePage, varptr(lpCPInfo)   ; 戻り値は stat
; CodePage : DWORD -> "sptr"
; lpCPInfo : CPINFO* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetCPInfo "GetCPInfo" int, var
; res = GetCPInfo(CodePage, lpCPInfo)
; CodePage : DWORD -> "int"
; lpCPInfo : CPINFO* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetCPInfo(DWORD CodePage, CPINFO* lpCPInfo)
#uselib "KERNEL32.dll"
#cfunc global GetCPInfo "GetCPInfo" int, var
; res = GetCPInfo(CodePage, lpCPInfo)
; CodePage : DWORD -> "int"
; lpCPInfo : CPINFO* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetCPInfo = kernel32.NewProc("GetCPInfo")
)

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