Win32 API 日本語リファレンス
ホームSystem.WindowsProgramming › uaw_wcscpy

uaw_wcscpy

関数
アドレス未整列対応版でワイド文字列をコピーする。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

WORD* uaw_wcscpy(
    WORD* Destination,
    WORD* Source
);

パラメーター

名前方向説明
DestinationWORD*outコピー先のワイド文字列バッファへのポインタ。十分な領域が必要。
SourceWORD*inコピー元のNUL終端ワイド文字列へのポインタ。

戻り値の型: WORD*

各言語での呼び出し定義

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

WORD* uaw_wcscpy(
    WORD* Destination,
    WORD* Source
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern IntPtr uaw_wcscpy(
    out ushort Destination,   // WORD* out
    ref ushort Source   // WORD*
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function uaw_wcscpy(
    <Out> ByRef Destination As UShort,   ' WORD* out
    ByRef Source As UShort   ' WORD*
) As IntPtr
End Function
' Destination : WORD* out
' Source : WORD*
Declare PtrSafe Function uaw_wcscpy Lib "kernel32" ( _
    ByRef Destination As Integer, _
    ByRef Source As Integer) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

uaw_wcscpy = ctypes.windll.kernel32.uaw_wcscpy
uaw_wcscpy.restype = ctypes.c_void_p
uaw_wcscpy.argtypes = [
    ctypes.POINTER(ctypes.c_ushort),  # Destination : WORD* out
    ctypes.POINTER(ctypes.c_ushort),  # Source : WORD*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
uaw_wcscpy = Fiddle::Function.new(
  lib['uaw_wcscpy'],
  [
    Fiddle::TYPE_VOIDP,  # Destination : WORD* out
    Fiddle::TYPE_VOIDP,  # Source : WORD*
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "kernel32")]
extern "system" {
    fn uaw_wcscpy(
        Destination: *mut u16,  // WORD* out
        Source: *mut u16  // WORD*
    ) -> *mut u16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern IntPtr uaw_wcscpy(out ushort Destination, ref ushort Source);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_uaw_wcscpy' -Namespace Win32 -PassThru
# $api::uaw_wcscpy(Destination, Source)
#uselib "KERNEL32.dll"
#func global uaw_wcscpy "uaw_wcscpy" sptr, sptr
; uaw_wcscpy varptr(Destination), varptr(Source)   ; 戻り値は stat
; Destination : WORD* out -> "sptr"
; Source : WORD* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global uaw_wcscpy "uaw_wcscpy" var, var
; res = uaw_wcscpy(Destination, Source)
; Destination : WORD* out -> "var"
; Source : WORD* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WORD* uaw_wcscpy(WORD* Destination, WORD* Source)
#uselib "KERNEL32.dll"
#cfunc global uaw_wcscpy "uaw_wcscpy" var, var
; res = uaw_wcscpy(Destination, Source)
; Destination : WORD* out -> "var"
; Source : WORD* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procuaw_wcscpy = kernel32.NewProc("uaw_wcscpy")
)

// Destination (WORD* out), Source (WORD*)
r1, _, err := procuaw_wcscpy.Call(
	uintptr(Destination),
	uintptr(Source),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WORD*
function uaw_wcscpy(
  Destination: Pointer;   // WORD* out
  Source: Pointer   // WORD*
): Pointer; stdcall;
  external 'KERNEL32.dll' name 'uaw_wcscpy';
result := DllCall("KERNEL32\uaw_wcscpy"
    , "Ptr", Destination   ; WORD* out
    , "Ptr", Source   ; WORD*
    , "Ptr")   ; return: WORD*
●uaw_wcscpy(Destination, Source) = DLL("KERNEL32.dll", "void* uaw_wcscpy(void*, void*)")
# 呼び出し: uaw_wcscpy(Destination, Source)
# Destination : WORD* out -> "void*"
# Source : WORD* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn uaw_wcscpy(
    Destination: [*c]u16, // WORD* out
    Source: [*c]u16 // WORD*
) callconv(std.os.windows.WINAPI) [*c]u16;
proc uaw_wcscpy(
    Destination: ptr uint16,  # WORD* out
    Source: ptr uint16  # WORD*
): ptr uint16 {.importc: "uaw_wcscpy", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
ushort* uaw_wcscpy(
    ushort* Destination,   // WORD* out
    ushort* Source   // WORD*
);
ccall((:uaw_wcscpy, "KERNEL32.dll"), stdcall, Ptr{UInt16},
      (Ptr{UInt16}, Ptr{UInt16}),
      Destination, Source)
# Destination : WORD* out -> Ptr{UInt16}
# Source : WORD* -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint16_t* uaw_wcscpy(
    uint16_t* Destination,
    uint16_t* Source);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.uaw_wcscpy(Destination, Source)
-- Destination : WORD* out
-- Source : WORD*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const uaw_wcscpy = lib.func('__stdcall', 'uaw_wcscpy', 'uint16_t *', ['uint16_t *', 'uint16_t *']);
// uaw_wcscpy(Destination, Source)
// Destination : WORD* out -> 'uint16_t *'
// Source : WORD* -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  uaw_wcscpy: { parameters: ["pointer", "pointer"], result: "pointer" },
});
// lib.symbols.uaw_wcscpy(Destination, Source)
// Destination : WORD* out -> "pointer"
// Source : WORD* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint16_t* uaw_wcscpy(
    uint16_t* Destination,
    uint16_t* Source);
C, "KERNEL32.dll");
// $ffi->uaw_wcscpy(Destination, Source);
// Destination : WORD* out
// Source : WORD*
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    Pointer uaw_wcscpy(
        ShortByReference Destination,   // WORD* out
        ShortByReference Source   // WORD*
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun uaw_wcscpy = uaw_wcscpy(
    Destination : UInt16*,   # WORD* out
    Source : UInt16*   # WORD*
  ) : UInt16*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef uaw_wcscpyNative = Pointer<Uint16> Function(Pointer<Uint16>, Pointer<Uint16>);
typedef uaw_wcscpyDart = Pointer<Uint16> Function(Pointer<Uint16>, Pointer<Uint16>);
final uaw_wcscpy = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<uaw_wcscpyNative, uaw_wcscpyDart>('uaw_wcscpy');
// Destination : WORD* out -> Pointer<Uint16>
// Source : WORD* -> Pointer<Uint16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function uaw_wcscpy(
  Destination: Pointer;   // WORD* out
  Source: Pointer   // WORD*
): Pointer; stdcall;
  external 'KERNEL32.dll' name 'uaw_wcscpy';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "uaw_wcscpy"
  c_uaw_wcscpy :: Ptr Word16 -> Ptr Word16 -> IO (Ptr Word16)
-- Destination : WORD* out -> Ptr Word16
-- Source : WORD* -> Ptr Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let uaw_wcscpy =
  foreign "uaw_wcscpy"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> returning (ptr uint16_t))
(* Destination : WORD* out -> (ptr uint16_t) *)
(* Source : WORD* -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("uaw_wcscpy" uaw-wcscpy :convention :stdcall) :pointer
  (destination :pointer)   ; WORD* out
  (source :pointer))   ; WORD*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $uaw_wcscpy = Win32::API::More->new('KERNEL32',
    'LPVOID uaw_wcscpy(LPVOID Destination, LPVOID Source)');
# my $ret = $uaw_wcscpy->Call($Destination, $Source);
# Destination : WORD* out -> LPVOID
# Source : WORD* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。