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

u_uastrncpy

関数
ASCII文字列をn文字までUCharに変換コピーする。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

WORD* u_uastrncpy(
    WORD* dst,
    LPCSTR src,
    INT n
);

パラメーター

名前方向説明
dstWORD*inout変換コピー先のUTF-16バッファへのポインタ。
srcLPCSTRinコピー元の不変ASCII(char)文字列へのポインタ。
nINTinコピーする最大UChar数。

戻り値の型: WORD*

各言語での呼び出し定義

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

WORD* u_uastrncpy(
    WORD* dst,
    LPCSTR src,
    INT n
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr u_uastrncpy(
    ref ushort dst,   // WORD* in/out
    [MarshalAs(UnmanagedType.LPStr)] string src,   // LPCSTR
    int n   // INT
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function u_uastrncpy(
    ByRef dst As UShort,   ' WORD* in/out
    <MarshalAs(UnmanagedType.LPStr)> src As String,   ' LPCSTR
    n As Integer   ' INT
) As IntPtr
End Function
' dst : WORD* in/out
' src : LPCSTR
' n : INT
Declare PtrSafe Function u_uastrncpy Lib "icuuc" ( _
    ByRef dst As Integer, _
    ByVal src As String, _
    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_uastrncpy = ctypes.cdll.icuuc.u_uastrncpy
u_uastrncpy.restype = ctypes.c_void_p
u_uastrncpy.argtypes = [
    ctypes.POINTER(ctypes.c_ushort),  # dst : WORD* in/out
    wintypes.LPCSTR,  # src : LPCSTR
    ctypes.c_int,  # n : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
u_uastrncpy = Fiddle::Function.new(
  lib['u_uastrncpy'],
  [
    Fiddle::TYPE_VOIDP,  # dst : WORD* in/out
    Fiddle::TYPE_VOIDP,  # src : LPCSTR
    Fiddle::TYPE_INT,  # n : INT
  ],
  Fiddle::TYPE_VOIDP, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn u_uastrncpy(
        dst: *mut u16,  // WORD* in/out
        src: *const u8,  // LPCSTR
        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_uastrncpy(ref ushort dst, [MarshalAs(UnmanagedType.LPStr)] string src, int n);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_u_uastrncpy' -Namespace Win32 -PassThru
# $api::u_uastrncpy(dst, src, n)
#uselib "icuuc.dll"
#func global u_uastrncpy "u_uastrncpy" sptr, sptr, sptr
; u_uastrncpy varptr(dst), src, n   ; 戻り値は stat
; dst : WORD* in/out -> "sptr"
; src : LPCSTR -> "sptr"
; n : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "icuuc.dll"
#cfunc global u_uastrncpy "u_uastrncpy" var, str, int
; res = u_uastrncpy(dst, src, n)
; dst : WORD* in/out -> "var"
; src : LPCSTR -> "str"
; n : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WORD* u_uastrncpy(WORD* dst, LPCSTR src, INT n)
#uselib "icuuc.dll"
#cfunc global u_uastrncpy "u_uastrncpy" var, str, int
; res = u_uastrncpy(dst, src, n)
; dst : WORD* in/out -> "var"
; src : LPCSTR -> "str"
; n : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procu_uastrncpy = icuuc.NewProc("u_uastrncpy")
)

// dst (WORD* in/out), src (LPCSTR), n (INT)
r1, _, err := procu_uastrncpy.Call(
	uintptr(dst),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(src))),
	uintptr(n),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WORD*
function u_uastrncpy(
  dst: Pointer;   // WORD* in/out
  src: PAnsiChar;   // LPCSTR
  n: Integer   // INT
): Pointer; cdecl;
  external 'icuuc.dll' name 'u_uastrncpy';
result := DllCall("icuuc\u_uastrncpy"
    , "Ptr", dst   ; WORD* in/out
    , "AStr", src   ; LPCSTR
    , "Int", n   ; INT
    , "Cdecl Ptr")   ; return: WORD*
●u_uastrncpy(dst, src, n) = DLL("icuuc.dll", "void* u_uastrncpy(void*, char*, int)")
# 呼び出し: u_uastrncpy(dst, src, n)
# dst : WORD* in/out -> "void*"
# src : LPCSTR -> "char*"
# 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_uastrncpy(
    dst: [*c]u16, // WORD* in/out
    src: [*c]const u8, // LPCSTR
    n: i32 // INT
) callconv(.c) [*c]u16;
proc u_uastrncpy(
    dst: ptr uint16,  # WORD* in/out
    src: cstring,  # LPCSTR
    n: int32  # INT
): ptr uint16 {.importc: "u_uastrncpy", cdecl, dynlib: "icuuc.dll".}
pragma(lib, "icuuc");
extern(C)
ushort* u_uastrncpy(
    ushort* dst,   // WORD* in/out
    const(char)* src,   // LPCSTR
    int n   // INT
);
ccall((:u_uastrncpy, "icuuc.dll"), Ptr{UInt16},
      (Ptr{UInt16}, Cstring, Int32),
      dst, src, n)
# dst : WORD* in/out -> Ptr{UInt16}
# src : LPCSTR -> Cstring
# n : INT -> Int32
local ffi = require("ffi")
ffi.cdef[[
uint16_t* u_uastrncpy(
    uint16_t* dst,
    const char* src,
    int32_t n);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.u_uastrncpy(dst, src, n)
-- dst : WORD* in/out
-- src : LPCSTR
-- n : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const u_uastrncpy = lib.func('__cdecl', 'u_uastrncpy', 'uint16_t *', ['uint16_t *', 'str', 'int32_t']);
// u_uastrncpy(dst, src, n)
// dst : WORD* in/out -> 'uint16_t *'
// src : LPCSTR -> 'str'
// n : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("icuuc.dll", {
  u_uastrncpy: { parameters: ["pointer", "buffer", "i32"], result: "pointer" },
});
// lib.symbols.u_uastrncpy(dst, src, n)
// dst : WORD* in/out -> "pointer"
// src : LPCSTR -> "buffer"
// n : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint16_t* u_uastrncpy(
    uint16_t* dst,
    const char* src,
    int32_t n);
C, "icuuc.dll");
// $ffi->u_uastrncpy(dst, src, n);
// dst : WORD* in/out
// src : LPCSTR
// 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_uastrncpy(
        ShortByReference dst,   // WORD* in/out
        String src,   // LPCSTR
        int n   // INT
    );
}
@[Link("icuuc")]
lib Libicuuc
  fun u_uastrncpy = u_uastrncpy(
    dst : UInt16*,   # WORD* in/out
    src : UInt8*,   # LPCSTR
    n : Int32   # INT
  ) : UInt16*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef u_uastrncpyNative = Pointer<Uint16> Function(Pointer<Uint16>, Pointer<Utf8>, Int32);
typedef u_uastrncpyDart = Pointer<Uint16> Function(Pointer<Uint16>, Pointer<Utf8>, int);
final u_uastrncpy = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<u_uastrncpyNative, u_uastrncpyDart>('u_uastrncpy');
// dst : WORD* in/out -> Pointer<Uint16>
// src : LPCSTR -> Pointer<Utf8>
// n : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function u_uastrncpy(
  dst: Pointer;   // WORD* in/out
  src: PAnsiChar;   // LPCSTR
  n: Integer   // INT
): Pointer; cdecl;
  external 'icuuc.dll' name 'u_uastrncpy';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "u_uastrncpy"
  c_u_uastrncpy :: Ptr Word16 -> CString -> Int32 -> IO (Ptr Word16)
-- dst : WORD* in/out -> Ptr Word16
-- src : LPCSTR -> CString
-- n : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let u_uastrncpy =
  foreign "u_uastrncpy"
    ((ptr uint16_t) @-> string @-> int32_t @-> returning (ptr uint16_t))
(* dst : WORD* in/out -> (ptr uint16_t) *)
(* src : LPCSTR -> string *)
(* 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_uastrncpy" u-uastrncpy :convention :cdecl) :pointer
  (dst :pointer)   ; WORD* in/out
  (src :string)   ; LPCSTR
  (n :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $u_uastrncpy = Win32::API::More->new('icuuc',
    'LPVOID u_uastrncpy(LPVOID dst, LPCSTR src, int n)');
# my $ret = $u_uastrncpy->Call($dst, $src, $n);
# dst : WORD* in/out -> LPVOID
# src : LPCSTR -> LPCSTR
# n : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。