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

IsDBCSLeadByteEx

関数
指定コードページでバイトがDBCS先頭バイトか判定する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL IsDBCSLeadByteEx(
    DWORD CodePage,
    BYTE TestChar
);

パラメーター

名前方向説明
CodePageDWORDin

リードバイトの範囲を確認するために使用するコードページの識別子。このパラメーターには、Unicode and Character Set Constants で定義されているコードページ識別子のいずれか、または以下の定義済みの値のいずれかを指定できます。この関数はコードページ 932、936、949、950、1361 でのみリードバイト値を検証します。

意味
CP_ACP
システム既定の Windows ANSI コードページを使用します。
CP_MACCP
システム既定の Macintosh コードページを使用します。
CP_OEMCP
システム既定の OEM コードページを使用します。
CP_THREAD_ACP
現在のスレッドの Windows ANSI コードページを使用します。
TestCharBYTEinテストする文字。

戻り値の型: BOOL

公式ドキュメント

指定した文字がリードバイトになり得るかどうかを判定します。リードバイトとは、コードページのダブルバイト文字セット (DBCS) における 2 バイト文字の先頭バイトのことです。

戻り値

バイトがリードバイトである場合は 0 以外の値を返します。バイトがリードバイトでない場合、または文字がシングルバイト文字である場合は 0 を返します。拡張エラー情報を取得するには、アプリケーションから GetLastError を呼び出すことができます。

解説(Remarks)

Note この関数はトレイルバイトの有無や妥当性を検証しません。そのため、IsDBCSLeadByte を使用するアプリケーションがリードバイトとして報告したシーケンスを、MultiByteToWideChar が認識しない場合があります。アプリケーションは MultiByteToWideChar の結果と容易に同期がとれなくなり、予期しないエラーやバッファーサイズの不一致を招くおそれがあります。
一般に、コードページデータの低レベルな操作を試みるのではなく、アプリケーションは MultiByteToWideChar を使用してデータを UTF-16 に変換し、そのエンコーディングで処理すべきです。

リードバイト値は個々の DBCS に固有です。一部のバイト値は、単一のコードページ内で DBCS 文字のリードバイトとトレイルバイトの両方として現れることがあります。したがって、IsDBCSLeadByteEx はリードバイトになり得る値であることを示せるにすぎません。

DBCS 文字列を正しく解釈するために、アプリケーションは通常、文字列の先頭から前方へスキャンし、リードバイトに遭遇したことを記録しながら、次のバイトを同じ文字の後続部分として扱います。後方へ戻る場合、アプリケーションは独自のアルゴリズムを開発しようとするのではなく、CharPrevExA を使用すべきです。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

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

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

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procIsDBCSLeadByteEx = kernel32.NewProc("IsDBCSLeadByteEx")
)

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

extern "kernel32" fn IsDBCSLeadByteEx(
    CodePage: u32, // DWORD
    TestChar: u8 // BYTE
) callconv(std.os.windows.WINAPI) i32;
proc IsDBCSLeadByteEx(
    CodePage: uint32,  # DWORD
    TestChar: uint8  # BYTE
): int32 {.importc: "IsDBCSLeadByteEx", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int IsDBCSLeadByteEx(
    uint CodePage,   // DWORD
    ubyte TestChar   // BYTE
);
ccall((:IsDBCSLeadByteEx, "KERNEL32.dll"), stdcall, Int32,
      (UInt32, UInt8),
      CodePage, TestChar)
# CodePage : DWORD -> UInt32
# TestChar : BYTE -> UInt8
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t IsDBCSLeadByteEx(
    uint32_t CodePage,
    uint8_t TestChar);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.IsDBCSLeadByteEx(CodePage, TestChar)
-- CodePage : DWORD
-- TestChar : BYTE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const IsDBCSLeadByteEx = lib.func('__stdcall', 'IsDBCSLeadByteEx', 'int32_t', ['uint32_t', 'uint8_t']);
// IsDBCSLeadByteEx(CodePage, TestChar)
// CodePage : DWORD -> 'uint32_t'
// TestChar : BYTE -> 'uint8_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  IsDBCSLeadByteEx: { parameters: ["u32", "u8"], result: "i32" },
});
// lib.symbols.IsDBCSLeadByteEx(CodePage, TestChar)
// CodePage : DWORD -> "u32"
// TestChar : BYTE -> "u8"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t IsDBCSLeadByteEx(
    uint32_t CodePage,
    uint8_t TestChar);
C, "KERNEL32.dll");
// $ffi->IsDBCSLeadByteEx(CodePage, TestChar);
// CodePage : DWORD
// TestChar : BYTE
// 構造体/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);
    boolean IsDBCSLeadByteEx(
        int CodePage,   // DWORD
        byte TestChar   // BYTE
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun IsDBCSLeadByteEx = IsDBCSLeadByteEx(
    CodePage : UInt32,   # DWORD
    TestChar : UInt8   # BYTE
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef IsDBCSLeadByteExNative = Int32 Function(Uint32, Uint8);
typedef IsDBCSLeadByteExDart = int Function(int, int);
final IsDBCSLeadByteEx = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<IsDBCSLeadByteExNative, IsDBCSLeadByteExDart>('IsDBCSLeadByteEx');
// CodePage : DWORD -> Uint32
// TestChar : BYTE -> Uint8
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function IsDBCSLeadByteEx(
  CodePage: DWORD;   // DWORD
  TestChar: Byte   // BYTE
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'IsDBCSLeadByteEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "IsDBCSLeadByteEx"
  c_IsDBCSLeadByteEx :: Word32 -> Word8 -> IO CInt
-- CodePage : DWORD -> Word32
-- TestChar : BYTE -> Word8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let isdbcsleadbyteex =
  foreign "IsDBCSLeadByteEx"
    (uint32_t @-> uint8_t @-> returning int32_t)
(* CodePage : DWORD -> uint32_t *)
(* TestChar : BYTE -> uint8_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("IsDBCSLeadByteEx" is-dbcslead-byte-ex :convention :stdcall) :int32
  (code-page :uint32)   ; DWORD
  (test-char :uint8))   ; BYTE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $IsDBCSLeadByteEx = Win32::API::More->new('KERNEL32',
    'BOOL IsDBCSLeadByteEx(DWORD CodePage, BYTE TestChar)');
# my $ret = $IsDBCSLeadByteEx->Call($CodePage, $TestChar);
# CodePage : DWORD -> DWORD
# TestChar : BYTE -> BYTE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
公式の関連項目