ホーム › Globalization › u_austrncpy
u_austrncpy
関数UChar文字列をn文字までASCIIに変換コピーする。
シグネチャ
// icuuc.dll
#include <windows.h>
LPSTR u_austrncpy(
LPSTR dst,
const WORD* src,
INT n
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| dst | LPSTR | in | 変換コピー先の不変ASCII(char)バッファへのポインタ。 |
| src | WORD* | in | コピー元のUTF-16文字列へのポインタ。 |
| n | INT | in | コピーする最大char数。 |
戻り値の型: LPSTR
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
LPSTR u_austrncpy(
LPSTR dst,
const WORD* src,
INT n
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr u_austrncpy(
[MarshalAs(UnmanagedType.LPStr)] string dst, // LPSTR
ref ushort src, // WORD*
int n // INT
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function u_austrncpy(
<MarshalAs(UnmanagedType.LPStr)> dst As String, ' LPSTR
ByRef src As UShort, ' WORD*
n As Integer ' INT
) As IntPtr
End Function' dst : LPSTR
' src : WORD*
' n : INT
Declare PtrSafe Function u_austrncpy Lib "icuuc" ( _
ByVal dst As String, _
ByRef src As Integer, _
ByVal n As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
u_austrncpy = ctypes.cdll.icuuc.u_austrncpy
u_austrncpy.restype = wintypes.LPSTR
u_austrncpy.argtypes = [
wintypes.LPCSTR, # dst : LPSTR
ctypes.POINTER(ctypes.c_ushort), # src : WORD*
ctypes.c_int, # n : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
u_austrncpy = Fiddle::Function.new(
lib['u_austrncpy'],
[
Fiddle::TYPE_VOIDP, # dst : LPSTR
Fiddle::TYPE_VOIDP, # src : WORD*
Fiddle::TYPE_INT, # n : INT
],
Fiddle::TYPE_VOIDP, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn u_austrncpy(
dst: *mut u8, // LPSTR
src: *const u16, // WORD*
n: i32 // INT
) -> *mut u8;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr u_austrncpy([MarshalAs(UnmanagedType.LPStr)] string dst, ref ushort src, int n);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_u_austrncpy' -Namespace Win32 -PassThru
# $api::u_austrncpy(dst, src, n)#uselib "icuuc.dll"
#func global u_austrncpy "u_austrncpy" sptr, sptr, sptr
; u_austrncpy dst, varptr(src), n ; 戻り値は stat
; dst : LPSTR -> "sptr"
; src : WORD* -> "sptr"
; n : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global u_austrncpy "u_austrncpy" str, var, int ; res = u_austrncpy(dst, src, n) ; dst : LPSTR -> "str" ; src : WORD* -> "var" ; n : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global u_austrncpy "u_austrncpy" str, sptr, int ; res = u_austrncpy(dst, varptr(src), n) ; dst : LPSTR -> "str" ; src : WORD* -> "sptr" ; n : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; LPSTR u_austrncpy(LPSTR dst, WORD* src, INT n) #uselib "icuuc.dll" #cfunc global u_austrncpy "u_austrncpy" str, var, int ; res = u_austrncpy(dst, src, n) ; dst : LPSTR -> "str" ; src : WORD* -> "var" ; n : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; LPSTR u_austrncpy(LPSTR dst, WORD* src, INT n) #uselib "icuuc.dll" #cfunc global u_austrncpy "u_austrncpy" str, intptr, int ; res = u_austrncpy(dst, varptr(src), n) ; dst : LPSTR -> "str" ; src : WORD* -> "intptr" ; n : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procu_austrncpy = icuuc.NewProc("u_austrncpy")
)
// dst (LPSTR), src (WORD*), n (INT)
r1, _, err := procu_austrncpy.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(dst))),
uintptr(src),
uintptr(n),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // LPSTRfunction u_austrncpy(
dst: PAnsiChar; // LPSTR
src: Pointer; // WORD*
n: Integer // INT
): PAnsiChar; cdecl;
external 'icuuc.dll' name 'u_austrncpy';result := DllCall("icuuc\u_austrncpy"
, "AStr", dst ; LPSTR
, "Ptr", src ; WORD*
, "Int", n ; INT
, "Cdecl Ptr") ; return: LPSTR●u_austrncpy(dst, src, n) = DLL("icuuc.dll", "char* u_austrncpy(char*, void*, int)")
# 呼び出し: u_austrncpy(dst, src, n)
# dst : LPSTR -> "char*"
# src : WORD* -> "void*"
# n : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。const std = @import("std");
extern "icuuc" fn u_austrncpy(
dst: [*c]const u8, // LPSTR
src: [*c]u16, // WORD*
n: i32 // INT
) callconv(.c) [*c]const u8;proc u_austrncpy(
dst: cstring, # LPSTR
src: ptr uint16, # WORD*
n: int32 # INT
): cstring {.importc: "u_austrncpy", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
const(char)* u_austrncpy(
const(char)* dst, // LPSTR
ushort* src, // WORD*
int n // INT
);ccall((:u_austrncpy, "icuuc.dll"), Cstring,
(Cstring, Ptr{UInt16}, Int32),
dst, src, n)
# dst : LPSTR -> Cstring
# src : WORD* -> Ptr{UInt16}
# n : INT -> Int32local ffi = require("ffi")
ffi.cdef[[
const char* u_austrncpy(
const char* dst,
uint16_t* src,
int32_t n);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.u_austrncpy(dst, src, n)
-- dst : LPSTR
-- src : WORD*
-- n : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const u_austrncpy = lib.func('__cdecl', 'u_austrncpy', 'void *', ['str', 'uint16_t *', 'int32_t']);
// u_austrncpy(dst, src, n)
// dst : LPSTR -> 'str'
// src : WORD* -> 'uint16_t *'
// n : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
u_austrncpy: { parameters: ["buffer", "pointer", "i32"], result: "pointer" },
});
// lib.symbols.u_austrncpy(dst, src, n)
// dst : LPSTR -> "buffer"
// src : WORD* -> "pointer"
// n : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
const char* u_austrncpy(
const char* dst,
uint16_t* src,
int32_t n);
C, "icuuc.dll");
// $ffi->u_austrncpy(dst, src, n);
// dst : LPSTR
// src : WORD*
// n : INT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Icuuc extends Library {
Icuuc INSTANCE = Native.load("icuuc", Icuuc.class);
Pointer u_austrncpy(
String dst, // LPSTR
ShortByReference src, // WORD*
int n // INT
);
}@[Link("icuuc")]
lib Libicuuc
fun u_austrncpy = u_austrncpy(
dst : UInt8*, # LPSTR
src : UInt16*, # WORD*
n : Int32 # INT
) : UInt8*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef u_austrncpyNative = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Uint16>, Int32);
typedef u_austrncpyDart = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Uint16>, int);
final u_austrncpy = DynamicLibrary.open('icuuc.dll')
.lookupFunction<u_austrncpyNative, u_austrncpyDart>('u_austrncpy');
// dst : LPSTR -> Pointer<Utf8>
// src : WORD* -> Pointer<Uint16>
// n : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function u_austrncpy(
dst: PAnsiChar; // LPSTR
src: Pointer; // WORD*
n: Integer // INT
): PAnsiChar; cdecl;
external 'icuuc.dll' name 'u_austrncpy';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "u_austrncpy"
c_u_austrncpy :: CString -> Ptr Word16 -> Int32 -> IO CString
-- dst : LPSTR -> CString
-- src : WORD* -> Ptr Word16
-- n : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let u_austrncpy =
foreign "u_austrncpy"
(string @-> (ptr uint16_t) @-> int32_t @-> returning string)
(* dst : LPSTR -> string *)
(* src : WORD* -> (ptr uint16_t) *)
(* n : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library icuuc (t "icuuc.dll"))
(cffi:use-foreign-library icuuc)
(cffi:defcfun ("u_austrncpy" u-austrncpy :convention :cdecl) :string
(dst :string) ; LPSTR
(src :pointer) ; WORD*
(n :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $u_austrncpy = Win32::API::More->new('icuuc',
'LPSTR u_austrncpy(LPCSTR dst, LPVOID src, int n)');
# my $ret = $u_austrncpy->Call($dst, $src, $n);
# dst : LPSTR -> LPCSTR
# src : WORD* -> LPVOID
# n : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。