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

StrCatChainW

関数
指定位置にバッファ範囲内で文字列を連結する。
DLLSHLWAPI.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD StrCatChainW(
    LPWSTR pszDst,
    DWORD cchDst,
    DWORD ichAt,
    LPCWSTR pszSrc
);

パラメーター

名前方向説明
pszDstLPWSTRoutこの関数が正常に戻ったときに、null で終端された Unicode 文字列を受け取るバッファへのポインターです。
cchDstDWORDinコピー先バッファのサイズ (文字数単位)。このバッファは、両方の文字列に加えて終端の null 文字を保持できる十分なサイズである必要があります。バッファが小さすぎる場合、最終的な文字列は切り詰められます。
ichAtDWORDin追加を開始するコピー先バッファ内のオフセット。文字列が空でない場合は、この値に -1 を設定すると、現在格納されている文字数 (終端の null 文字を含まない) が自動的に計算されます。
pszSrcLPCWSTRinnull で終端されたコピー元 Unicode 文字列へのポインターです。

戻り値の型: DWORD

公式ドキュメント

2 つの Unicode 文字列を連結します。同じバッファに対して連結を繰り返し行う必要がある場合に使用します。

戻り値

型: DWORD

pszDst に追加された最後の文字の後にある null 文字のオフセットを返します。

解説(Remarks)

セキュリティに関する警告: この関数を誤って使用すると、アプリケーションのセキュリティが損なわれる可能性があります。最終的な文字列が null で終端されることは保証されません。次のいずれかの代替手段の使用を検討してください: StringCbCatExStringCbCatNExStringCchCatEx、または StringCchCatNEx。続行する前に、セキュリティに関する考慮事項: Microsoft Windows シェル を確認してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

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

StrCatChainW = ctypes.windll.shlwapi.StrCatChainW
StrCatChainW.restype = wintypes.DWORD
StrCatChainW.argtypes = [
    wintypes.LPWSTR,  # pszDst : LPWSTR out
    wintypes.DWORD,  # cchDst : DWORD
    wintypes.DWORD,  # ichAt : DWORD
    wintypes.LPCWSTR,  # pszSrc : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procStrCatChainW = shlwapi.NewProc("StrCatChainW")
)

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

extern "shlwapi" fn StrCatChainW(
    pszDst: [*c]u16, // LPWSTR out
    cchDst: u32, // DWORD
    ichAt: u32, // DWORD
    pszSrc: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) u32;
proc StrCatChainW(
    pszDst: ptr uint16,  # LPWSTR out
    cchDst: uint32,  # DWORD
    ichAt: uint32,  # DWORD
    pszSrc: WideCString  # LPCWSTR
): uint32 {.importc: "StrCatChainW", stdcall, dynlib: "SHLWAPI.dll".}
pragma(lib, "shlwapi");
extern(Windows)
uint StrCatChainW(
    wchar* pszDst,   // LPWSTR out
    uint cchDst,   // DWORD
    uint ichAt,   // DWORD
    const(wchar)* pszSrc   // LPCWSTR
);
ccall((:StrCatChainW, "SHLWAPI.dll"), stdcall, UInt32,
      (Ptr{UInt16}, UInt32, UInt32, Cwstring),
      pszDst, cchDst, ichAt, pszSrc)
# pszDst : LPWSTR out -> Ptr{UInt16}
# cchDst : DWORD -> UInt32
# ichAt : DWORD -> UInt32
# pszSrc : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t StrCatChainW(
    uint16_t* pszDst,
    uint32_t cchDst,
    uint32_t ichAt,
    const uint16_t* pszSrc);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.StrCatChainW(pszDst, cchDst, ichAt, pszSrc)
-- pszDst : LPWSTR out
-- cchDst : DWORD
-- ichAt : DWORD
-- pszSrc : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const StrCatChainW = lib.func('__stdcall', 'StrCatChainW', 'uint32_t', ['uint16_t *', 'uint32_t', 'uint32_t', 'str16']);
// StrCatChainW(pszDst, cchDst, ichAt, pszSrc)
// pszDst : LPWSTR out -> 'uint16_t *'
// cchDst : DWORD -> 'uint32_t'
// ichAt : DWORD -> 'uint32_t'
// pszSrc : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SHLWAPI.dll", {
  StrCatChainW: { parameters: ["buffer", "u32", "u32", "buffer"], result: "u32" },
});
// lib.symbols.StrCatChainW(pszDst, cchDst, ichAt, pszSrc)
// pszDst : LPWSTR out -> "buffer"
// cchDst : DWORD -> "u32"
// ichAt : DWORD -> "u32"
// pszSrc : LPCWSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t StrCatChainW(
    uint16_t* pszDst,
    uint32_t cchDst,
    uint32_t ichAt,
    const uint16_t* pszSrc);
C, "SHLWAPI.dll");
// $ffi->StrCatChainW(pszDst, cchDst, ichAt, pszSrc);
// pszDst : LPWSTR out
// cchDst : DWORD
// ichAt : DWORD
// pszSrc : LPCWSTR
// 構造体/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 Shlwapi extends StdCallLibrary {
    Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class);
    int StrCatChainW(
        char[] pszDst,   // LPWSTR out
        int cchDst,   // DWORD
        int ichAt,   // DWORD
        WString pszSrc   // LPCWSTR
    );
}
@[Link("shlwapi")]
lib LibSHLWAPI
  fun StrCatChainW = StrCatChainW(
    pszDst : UInt16*,   # LPWSTR out
    cchDst : UInt32,   # DWORD
    ichAt : UInt32,   # DWORD
    pszSrc : UInt16*   # LPCWSTR
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef StrCatChainWNative = Uint32 Function(Pointer<Utf16>, Uint32, Uint32, Pointer<Utf16>);
typedef StrCatChainWDart = int Function(Pointer<Utf16>, int, int, Pointer<Utf16>);
final StrCatChainW = DynamicLibrary.open('SHLWAPI.dll')
    .lookupFunction<StrCatChainWNative, StrCatChainWDart>('StrCatChainW');
// pszDst : LPWSTR out -> Pointer<Utf16>
// cchDst : DWORD -> Uint32
// ichAt : DWORD -> Uint32
// pszSrc : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function StrCatChainW(
  pszDst: PWideChar;   // LPWSTR out
  cchDst: DWORD;   // DWORD
  ichAt: DWORD;   // DWORD
  pszSrc: PWideChar   // LPCWSTR
): DWORD; stdcall;
  external 'SHLWAPI.dll' name 'StrCatChainW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "StrCatChainW"
  c_StrCatChainW :: CWString -> Word32 -> Word32 -> CWString -> IO Word32
-- pszDst : LPWSTR out -> CWString
-- cchDst : DWORD -> Word32
-- ichAt : DWORD -> Word32
-- pszSrc : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let strcatchainw =
  foreign "StrCatChainW"
    ((ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> returning uint32_t)
(* pszDst : LPWSTR out -> (ptr uint16_t) *)
(* cchDst : DWORD -> uint32_t *)
(* ichAt : DWORD -> uint32_t *)
(* pszSrc : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)

(cffi:defcfun ("StrCatChainW" str-cat-chain-w :convention :stdcall) :uint32
  (psz-dst :pointer)   ; LPWSTR out
  (cch-dst :uint32)   ; DWORD
  (ich-at :uint32)   ; DWORD
  (psz-src (:string :encoding :utf-16le)))   ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $StrCatChainW = Win32::API::More->new('SHLWAPI',
    'DWORD StrCatChainW(LPWSTR pszDst, DWORD cchDst, DWORD ichAt, LPCWSTR pszSrc)');
# my $ret = $StrCatChainW->Call($pszDst, $cchDst, $ichAt, $pszSrc);
# pszDst : LPWSTR out -> LPWSTR
# cchDst : DWORD -> DWORD
# ichAt : DWORD -> DWORD
# pszSrc : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。