ホーム › Globalization › u_strncpy
u_strncpy
関数UChar文字列を最大n文字までコピーする。
シグネチャ
// icuuc.dll
#include <windows.h>
WORD* u_strncpy(
WORD* dst,
const WORD* src,
INT n
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| dst | WORD* | inout |
| src | WORD* | in |
| n | INT | in |
戻り値の型: WORD*
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
WORD* u_strncpy(
WORD* dst,
const WORD* src,
INT n
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr u_strncpy(
ref ushort dst, // WORD* in/out
ref ushort src, // WORD*
int n // INT
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function u_strncpy(
ByRef dst As UShort, ' WORD* in/out
ByRef src As UShort, ' WORD*
n As Integer ' INT
) As IntPtr
End Function' dst : WORD* in/out
' src : WORD*
' n : INT
Declare PtrSafe Function u_strncpy Lib "icuuc" ( _
ByRef dst As Integer, _
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_strncpy = ctypes.cdll.icuuc.u_strncpy
u_strncpy.restype = ctypes.c_void_p
u_strncpy.argtypes = [
ctypes.POINTER(ctypes.c_ushort), # dst : WORD* in/out
ctypes.POINTER(ctypes.c_ushort), # src : WORD*
ctypes.c_int, # n : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
u_strncpy = Fiddle::Function.new(
lib['u_strncpy'],
[
Fiddle::TYPE_VOIDP, # dst : WORD* in/out
Fiddle::TYPE_VOIDP, # src : WORD*
Fiddle::TYPE_INT, # n : INT
],
Fiddle::TYPE_VOIDP, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn u_strncpy(
dst: *mut u16, // WORD* in/out
src: *const u16, // WORD*
n: i32 // INT
) -> *mut u16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr u_strncpy(ref ushort dst, ref ushort src, int n);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_u_strncpy' -Namespace Win32 -PassThru
# $api::u_strncpy(dst, src, n)#uselib "icuuc.dll"
#func global u_strncpy "u_strncpy" sptr, sptr, sptr
; u_strncpy varptr(dst), varptr(src), n ; 戻り値は stat
; dst : WORD* in/out -> "sptr"
; src : WORD* -> "sptr"
; n : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global u_strncpy "u_strncpy" var, var, int ; res = u_strncpy(dst, src, n) ; dst : WORD* in/out -> "var" ; src : WORD* -> "var" ; n : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global u_strncpy "u_strncpy" sptr, sptr, int ; res = u_strncpy(varptr(dst), varptr(src), n) ; dst : WORD* in/out -> "sptr" ; src : WORD* -> "sptr" ; n : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WORD* u_strncpy(WORD* dst, WORD* src, INT n) #uselib "icuuc.dll" #cfunc global u_strncpy "u_strncpy" var, var, int ; res = u_strncpy(dst, src, n) ; dst : WORD* in/out -> "var" ; src : WORD* -> "var" ; n : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WORD* u_strncpy(WORD* dst, WORD* src, INT n) #uselib "icuuc.dll" #cfunc global u_strncpy "u_strncpy" intptr, intptr, int ; res = u_strncpy(varptr(dst), varptr(src), n) ; dst : WORD* in/out -> "intptr" ; src : WORD* -> "intptr" ; n : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procu_strncpy = icuuc.NewProc("u_strncpy")
)
// dst (WORD* in/out), src (WORD*), n (INT)
r1, _, err := procu_strncpy.Call(
uintptr(dst),
uintptr(src),
uintptr(n),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WORD*function u_strncpy(
dst: Pointer; // WORD* in/out
src: Pointer; // WORD*
n: Integer // INT
): Pointer; cdecl;
external 'icuuc.dll' name 'u_strncpy';result := DllCall("icuuc\u_strncpy"
, "Ptr", dst ; WORD* in/out
, "Ptr", src ; WORD*
, "Int", n ; INT
, "Cdecl Ptr") ; return: WORD*●u_strncpy(dst, src, n) = DLL("icuuc.dll", "void* u_strncpy(void*, void*, int)")
# 呼び出し: u_strncpy(dst, src, n)
# dst : WORD* in/out -> "void*"
# src : WORD* -> "void*"
# n : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。