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

ucnv_getInvalidChars

関数
直近の変換で無効だったバイト列を取得する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

void ucnv_getInvalidChars(
    const UConverter* converter,
    LPSTR errBytes,
    CHAR* len,
    UErrorCode* err
);

パラメーター

名前方向
converterUConverter*in
errBytesLPSTRin
lenCHAR*inout
errUErrorCode*inout

戻り値の型: void

各言語での呼び出し定義

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

void ucnv_getInvalidChars(
    const UConverter* converter,
    LPSTR errBytes,
    CHAR* len,
    UErrorCode* err
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern void ucnv_getInvalidChars(
    ref IntPtr converter,   // UConverter*
    [MarshalAs(UnmanagedType.LPStr)] string errBytes,   // LPSTR
    IntPtr len,   // CHAR* in/out
    ref int err   // UErrorCode* in/out
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Sub ucnv_getInvalidChars(
    ByRef converter As IntPtr,   ' UConverter*
    <MarshalAs(UnmanagedType.LPStr)> errBytes As String,   ' LPSTR
    len As IntPtr,   ' CHAR* in/out
    ByRef err As Integer   ' UErrorCode* in/out
)
End Sub
' converter : UConverter*
' errBytes : LPSTR
' len : CHAR* in/out
' err : UErrorCode* in/out
Declare PtrSafe Sub ucnv_getInvalidChars Lib "icuuc" ( _
    ByRef converter As LongPtr, _
    ByVal errBytes As String, _
    ByVal len As LongPtr, _
    ByRef err As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ucnv_getInvalidChars = ctypes.cdll.icuuc.ucnv_getInvalidChars
ucnv_getInvalidChars.restype = None
ucnv_getInvalidChars.argtypes = [
    ctypes.c_void_p,  # converter : UConverter*
    wintypes.LPCSTR,  # errBytes : LPSTR
    ctypes.POINTER(ctypes.c_byte),  # len : CHAR* in/out
    ctypes.c_void_p,  # err : UErrorCode* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
ucnv_getInvalidChars = Fiddle::Function.new(
  lib['ucnv_getInvalidChars'],
  [
    Fiddle::TYPE_VOIDP,  # converter : UConverter*
    Fiddle::TYPE_VOIDP,  # errBytes : LPSTR
    Fiddle::TYPE_VOIDP,  # len : CHAR* in/out
    Fiddle::TYPE_VOIDP,  # err : UErrorCode* in/out
  ],
  Fiddle::TYPE_VOID, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn ucnv_getInvalidChars(
        converter: *const isize,  // UConverter*
        errBytes: *mut u8,  // LPSTR
        len: *mut i8,  // CHAR* in/out
        err: *mut i32  // UErrorCode* in/out
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void ucnv_getInvalidChars(ref IntPtr converter, [MarshalAs(UnmanagedType.LPStr)] string errBytes, IntPtr len, ref int err);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_ucnv_getInvalidChars' -Namespace Win32 -PassThru
# $api::ucnv_getInvalidChars(converter, errBytes, len, err)
#uselib "icuuc.dll"
#func global ucnv_getInvalidChars "ucnv_getInvalidChars" sptr, sptr, sptr, sptr
; ucnv_getInvalidChars converter, errBytes, varptr(len), err
; converter : UConverter* -> "sptr"
; errBytes : LPSTR -> "sptr"
; len : CHAR* in/out -> "sptr"
; err : UErrorCode* in/out -> "sptr"
出力引数:
#uselib "icuuc.dll"
#func global ucnv_getInvalidChars "ucnv_getInvalidChars" int, str, var, int
; ucnv_getInvalidChars converter, errBytes, len, err
; converter : UConverter* -> "int"
; errBytes : LPSTR -> "str"
; len : CHAR* in/out -> "var"
; err : UErrorCode* in/out -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void ucnv_getInvalidChars(UConverter* converter, LPSTR errBytes, CHAR* len, UErrorCode* err)
#uselib "icuuc.dll"
#func global ucnv_getInvalidChars "ucnv_getInvalidChars" int, str, var, int
; ucnv_getInvalidChars converter, errBytes, len, err
; converter : UConverter* -> "int"
; errBytes : LPSTR -> "str"
; len : CHAR* in/out -> "var"
; err : UErrorCode* in/out -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procucnv_getInvalidChars = icuuc.NewProc("ucnv_getInvalidChars")
)

// converter (UConverter*), errBytes (LPSTR), len (CHAR* in/out), err (UErrorCode* in/out)
r1, _, err := procucnv_getInvalidChars.Call(
	uintptr(converter),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(errBytes))),
	uintptr(len),
	uintptr(err),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
procedure ucnv_getInvalidChars(
  converter: Pointer;   // UConverter*
  errBytes: PAnsiChar;   // LPSTR
  len: Pointer;   // CHAR* in/out
  err: Pointer   // UErrorCode* in/out
); cdecl;
  external 'icuuc.dll' name 'ucnv_getInvalidChars';
result := DllCall("icuuc\ucnv_getInvalidChars"
    , "Ptr", converter   ; UConverter*
    , "AStr", errBytes   ; LPSTR
    , "Ptr", len   ; CHAR* in/out
    , "Ptr", err   ; UErrorCode* in/out
    , "Cdecl Int")   ; return: void
●ucnv_getInvalidChars(converter, errBytes, len, err) = DLL("icuuc.dll", "int ucnv_getInvalidChars(void*, char*, void*, void*)")
# 呼び出し: ucnv_getInvalidChars(converter, errBytes, len, err)
# converter : UConverter* -> "void*"
# errBytes : LPSTR -> "char*"
# len : CHAR* in/out -> "void*"
# err : UErrorCode* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。