Win32 API 日本語リファレンス
ホームUI.Shell › StrCpyW

StrCpyW

関数
文字列を別のバッファにコピーする。
DLLSHLWAPI.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

LPWSTR StrCpyW(
    LPWSTR psz1,
    LPCWSTR psz2
);

パラメーター

名前方向
psz1LPWSTRout
psz2LPCWSTRin

戻り値の型: LPWSTR

各言語での呼び出し定義

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

LPWSTR StrCpyW(
    LPWSTR psz1,
    LPCWSTR psz2
);
[DllImport("SHLWAPI.dll", ExactSpelling = true)]
static extern IntPtr StrCpyW(
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder psz1,   // LPWSTR out
    [MarshalAs(UnmanagedType.LPWStr)] string psz2   // LPCWSTR
);
<DllImport("SHLWAPI.dll", ExactSpelling:=True)>
Public Shared Function StrCpyW(
    <MarshalAs(UnmanagedType.LPWStr)> psz1 As System.Text.StringBuilder,   ' LPWSTR out
    <MarshalAs(UnmanagedType.LPWStr)> psz2 As String   ' LPCWSTR
) As IntPtr
End Function
' psz1 : LPWSTR out
' psz2 : LPCWSTR
Declare PtrSafe Function StrCpyW Lib "shlwapi" ( _
    ByVal psz1 As LongPtr, _
    ByVal psz2 As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

StrCpyW = ctypes.windll.shlwapi.StrCpyW
StrCpyW.restype = wintypes.LPWSTR
StrCpyW.argtypes = [
    wintypes.LPWSTR,  # psz1 : LPWSTR out
    wintypes.LPCWSTR,  # psz2 : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procStrCpyW = shlwapi.NewProc("StrCpyW")
)

// psz1 (LPWSTR out), psz2 (LPCWSTR)
r1, _, err := procStrCpyW.Call(
	uintptr(psz1),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(psz2))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LPWSTR
function StrCpyW(
  psz1: PWideChar;   // LPWSTR out
  psz2: PWideChar   // LPCWSTR
): PWideChar; stdcall;
  external 'SHLWAPI.dll' name 'StrCpyW';
result := DllCall("SHLWAPI\StrCpyW"
    , "Ptr", psz1   ; LPWSTR out
    , "WStr", psz2   ; LPCWSTR
    , "Ptr")   ; return: LPWSTR
●StrCpyW(psz1, psz2) = DLL("SHLWAPI.dll", "char* StrCpyW(char*, char*)")
# 呼び出し: StrCpyW(psz1, psz2)
# psz1 : LPWSTR out -> "char*"
# psz2 : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。