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

utf8_back1SafeBody

関数
UTF-8文字列で1文字分安全に後退した位置を取得する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

INT utf8_back1SafeBody(
    const BYTE* s,
    INT start,
    INT i
);

パラメーター

名前方向
sBYTE*in
startINTin
iINTin

戻り値の型: INT

各言語での呼び出し定義

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

INT utf8_back1SafeBody(
    const BYTE* s,
    INT start,
    INT i
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int utf8_back1SafeBody(
    IntPtr s,   // BYTE*
    int start,   // INT
    int i   // INT
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function utf8_back1SafeBody(
    s As IntPtr,   ' BYTE*
    start As Integer,   ' INT
    i As Integer   ' INT
) As Integer
End Function
' s : BYTE*
' start : INT
' i : INT
Declare PtrSafe Function utf8_back1SafeBody Lib "icuuc" ( _
    ByVal s As LongPtr, _
    ByVal start As Long, _
    ByVal i As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

utf8_back1SafeBody = ctypes.cdll.icuuc.utf8_back1SafeBody
utf8_back1SafeBody.restype = ctypes.c_int
utf8_back1SafeBody.argtypes = [
    ctypes.POINTER(ctypes.c_ubyte),  # s : BYTE*
    ctypes.c_int,  # start : INT
    ctypes.c_int,  # i : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
utf8_back1SafeBody = Fiddle::Function.new(
  lib['utf8_back1SafeBody'],
  [
    Fiddle::TYPE_VOIDP,  # s : BYTE*
    Fiddle::TYPE_INT,  # start : INT
    Fiddle::TYPE_INT,  # i : INT
  ],
  Fiddle::TYPE_INT, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn utf8_back1SafeBody(
        s: *const u8,  // BYTE*
        start: i32,  // INT
        i: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int utf8_back1SafeBody(IntPtr s, int start, int i);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_utf8_back1SafeBody' -Namespace Win32 -PassThru
# $api::utf8_back1SafeBody(s, start, i)
#uselib "icuuc.dll"
#func global utf8_back1SafeBody "utf8_back1SafeBody" sptr, sptr, sptr
; utf8_back1SafeBody varptr(s), start, i   ; 戻り値は stat
; s : BYTE* -> "sptr"
; start : INT -> "sptr"
; i : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "icuuc.dll"
#cfunc global utf8_back1SafeBody "utf8_back1SafeBody" var, int, int
; res = utf8_back1SafeBody(s, start, i)
; s : BYTE* -> "var"
; start : INT -> "int"
; i : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT utf8_back1SafeBody(BYTE* s, INT start, INT i)
#uselib "icuuc.dll"
#cfunc global utf8_back1SafeBody "utf8_back1SafeBody" var, int, int
; res = utf8_back1SafeBody(s, start, i)
; s : BYTE* -> "var"
; start : INT -> "int"
; i : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procutf8_back1SafeBody = icuuc.NewProc("utf8_back1SafeBody")
)

// s (BYTE*), start (INT), i (INT)
r1, _, err := procutf8_back1SafeBody.Call(
	uintptr(s),
	uintptr(start),
	uintptr(i),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function utf8_back1SafeBody(
  s: Pointer;   // BYTE*
  start: Integer;   // INT
  i: Integer   // INT
): Integer; cdecl;
  external 'icuuc.dll' name 'utf8_back1SafeBody';
result := DllCall("icuuc\utf8_back1SafeBody"
    , "Ptr", s   ; BYTE*
    , "Int", start   ; INT
    , "Int", i   ; INT
    , "Cdecl Int")   ; return: INT
●utf8_back1SafeBody(s, start, i) = DLL("icuuc.dll", "int utf8_back1SafeBody(void*, int, int)")
# 呼び出し: utf8_back1SafeBody(s, start, i)
# s : BYTE* -> "void*"
# start : INT -> "int"
# i : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。