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

u_austrncpy

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

シグネチャ

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

LPSTR u_austrncpy(
    LPSTR dst,
    const WORD* src,
    INT n
);

パラメーター

名前方向
dstLPSTRin
srcWORD*in
nINTin

戻り値の型: 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // LPSTR
function 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`,…) を使用。