StrCatW
関数二つの文字列を連結する。
シグネチャ
// SHLWAPI.dll
#include <windows.h>
LPWSTR StrCatW(
LPWSTR psz1,
LPCWSTR psz2
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| psz1 | LPWSTR | inout | null で終端する文字列へのポインター。この関数が正常に戻ると、この文字列には元の内容に文字列 psz2 を連結したものが格納されます。このバッファーは、両方の文字列と終端の null 文字を保持できる十分な大きさである必要があります。 |
| psz2 | LPCWSTR | in | psz1 に連結する、null で終端する文字列へのポインター。 |
戻り値の型: LPWSTR
公式ドキュメント
ある文字列を別の文字列に連結します。
戻り値
型: PTSTR
連結された文字列を保持する psz1 へのポインターを返します。
解説(Remarks)
セキュリティに関する警告: この関数を誤って使用すると、アプリケーションのセキュリティが損なわれる可能性があります。第 1 引数 psz1 は psz2 と終端の '\0' を保持できる十分な大きさである必要があります。そうでない場合、バッファーオーバーランが発生する可能性があります。バッファーオーバーランは、アクセス違反が発生した場合にアプリケーションに対するサービス拒否攻撃につながる可能性があります。最悪の場合、特に psz1 がスタックベースのバッファーである場合、バッファーオーバーランによって攻撃者がプロセスに実行可能なコードを注入できる可能性があります。次のいずれかの代替手段の使用を検討してください: StringCbCat、StringCbCatEx、StringCbCatN、StringCbCatNEx、StringCchCat、StringCchCatEx、StringCchCatN、または StringCchCatNEx。続行する前に、セキュリティに関する考慮事項: Microsoft Windows シェル を確認してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHLWAPI.dll
#include <windows.h>
LPWSTR StrCatW(
LPWSTR psz1,
LPCWSTR psz2
);[DllImport("SHLWAPI.dll", ExactSpelling = true)]
static extern IntPtr StrCatW(
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder psz1, // LPWSTR in/out
[MarshalAs(UnmanagedType.LPWStr)] string psz2 // LPCWSTR
);<DllImport("SHLWAPI.dll", ExactSpelling:=True)>
Public Shared Function StrCatW(
<MarshalAs(UnmanagedType.LPWStr)> psz1 As System.Text.StringBuilder, ' LPWSTR in/out
<MarshalAs(UnmanagedType.LPWStr)> psz2 As String ' LPCWSTR
) As IntPtr
End Function' psz1 : LPWSTR in/out
' psz2 : LPCWSTR
Declare PtrSafe Function StrCatW 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
StrCatW = ctypes.windll.shlwapi.StrCatW
StrCatW.restype = wintypes.LPWSTR
StrCatW.argtypes = [
wintypes.LPWSTR, # psz1 : LPWSTR in/out
wintypes.LPCWSTR, # psz2 : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
StrCatW = Fiddle::Function.new(
lib['StrCatW'],
[
Fiddle::TYPE_VOIDP, # psz1 : LPWSTR in/out
Fiddle::TYPE_VOIDP, # psz2 : LPCWSTR
],
Fiddle::TYPE_VOIDP)#[link(name = "shlwapi")]
extern "system" {
fn StrCatW(
psz1: *mut u16, // LPWSTR in/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 StrCatW([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder psz1, [MarshalAs(UnmanagedType.LPWStr)] string psz2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrCatW' -Namespace Win32 -PassThru
# $api::StrCatW(psz1, psz2)#uselib "SHLWAPI.dll"
#func global StrCatW "StrCatW" sptr, sptr
; StrCatW varptr(psz1), psz2 ; 戻り値は stat
; psz1 : LPWSTR in/out -> "sptr"
; psz2 : LPCWSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global StrCatW "StrCatW" var, wstr ; res = StrCatW(psz1, psz2) ; psz1 : LPWSTR in/out -> "var" ; psz2 : LPCWSTR -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global StrCatW "StrCatW" sptr, wstr ; res = StrCatW(varptr(psz1), psz2) ; psz1 : LPWSTR in/out -> "sptr" ; psz2 : LPCWSTR -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; LPWSTR StrCatW(LPWSTR psz1, LPCWSTR psz2) #uselib "SHLWAPI.dll" #cfunc global StrCatW "StrCatW" var, wstr ; res = StrCatW(psz1, psz2) ; psz1 : LPWSTR in/out -> "var" ; psz2 : LPCWSTR -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; LPWSTR StrCatW(LPWSTR psz1, LPCWSTR psz2) #uselib "SHLWAPI.dll" #cfunc global StrCatW "StrCatW" intptr, wstr ; res = StrCatW(varptr(psz1), psz2) ; psz1 : LPWSTR in/out -> "intptr" ; psz2 : LPCWSTR -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procStrCatW = shlwapi.NewProc("StrCatW")
)
// psz1 (LPWSTR in/out), psz2 (LPCWSTR)
r1, _, err := procStrCatW.Call(
uintptr(psz1),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(psz2))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // LPWSTRfunction StrCatW(
psz1: PWideChar; // LPWSTR in/out
psz2: PWideChar // LPCWSTR
): PWideChar; stdcall;
external 'SHLWAPI.dll' name 'StrCatW';result := DllCall("SHLWAPI\StrCatW"
, "Ptr", psz1 ; LPWSTR in/out
, "WStr", psz2 ; LPCWSTR
, "Ptr") ; return: LPWSTR●StrCatW(psz1, psz2) = DLL("SHLWAPI.dll", "char* StrCatW(char*, char*)")
# 呼び出し: StrCatW(psz1, psz2)
# psz1 : LPWSTR in/out -> "char*"
# psz2 : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shlwapi" fn StrCatW(
psz1: [*c]u16, // LPWSTR in/out
psz2: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) [*c]const u16;proc StrCatW(
psz1: ptr uint16, # LPWSTR in/out
psz2: WideCString # LPCWSTR
): WideCString {.importc: "StrCatW", stdcall, dynlib: "SHLWAPI.dll".}pragma(lib, "shlwapi");
extern(Windows)
const(wchar)* StrCatW(
wchar* psz1, // LPWSTR in/out
const(wchar)* psz2 // LPCWSTR
);ccall((:StrCatW, "SHLWAPI.dll"), stdcall, Cwstring,
(Ptr{UInt16}, Cwstring),
psz1, psz2)
# psz1 : LPWSTR in/out -> Ptr{UInt16}
# psz2 : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
const uint16_t* StrCatW(
uint16_t* psz1,
const uint16_t* psz2);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.StrCatW(psz1, psz2)
-- psz1 : LPWSTR in/out
-- psz2 : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const StrCatW = lib.func('__stdcall', 'StrCatW', 'void *', ['uint16_t *', 'str16']);
// StrCatW(psz1, psz2)
// psz1 : LPWSTR in/out -> 'uint16_t *'
// psz2 : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
StrCatW: { parameters: ["buffer", "buffer"], result: "pointer" },
});
// lib.symbols.StrCatW(psz1, psz2)
// psz1 : LPWSTR in/out -> "buffer"
// psz2 : LPCWSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
const uint16_t* StrCatW(
uint16_t* psz1,
const uint16_t* psz2);
C, "SHLWAPI.dll");
// $ffi->StrCatW(psz1, psz2);
// psz1 : LPWSTR in/out
// psz2 : 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);
Pointer StrCatW(
char[] psz1, // LPWSTR in/out
WString psz2 // LPCWSTR
);
}@[Link("shlwapi")]
lib LibSHLWAPI
fun StrCatW = StrCatW(
psz1 : UInt16*, # LPWSTR in/out
psz2 : UInt16* # LPCWSTR
) : UInt16*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef StrCatWNative = Pointer<Utf16> Function(Pointer<Utf16>, Pointer<Utf16>);
typedef StrCatWDart = Pointer<Utf16> Function(Pointer<Utf16>, Pointer<Utf16>);
final StrCatW = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<StrCatWNative, StrCatWDart>('StrCatW');
// psz1 : LPWSTR in/out -> Pointer<Utf16>
// psz2 : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function StrCatW(
psz1: PWideChar; // LPWSTR in/out
psz2: PWideChar // LPCWSTR
): PWideChar; stdcall;
external 'SHLWAPI.dll' name 'StrCatW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "StrCatW"
c_StrCatW :: CWString -> CWString -> IO CWString
-- psz1 : LPWSTR in/out -> CWString
-- psz2 : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let strcatw =
foreign "StrCatW"
((ptr uint16_t) @-> (ptr uint16_t) @-> returning (ptr uint16_t))
(* psz1 : LPWSTR in/out -> (ptr uint16_t) *)
(* psz2 : 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 ("StrCatW" str-cat-w :convention :stdcall) (:string :encoding :utf-16le)
(psz1 :pointer) ; LPWSTR in/out
(psz2 (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $StrCatW = Win32::API::More->new('SHLWAPI',
'LPWSTR StrCatW(LPWSTR psz1, LPCWSTR psz2)');
# my $ret = $StrCatW->Call($psz1, $psz2);
# psz1 : LPWSTR in/out -> LPWSTR
# psz2 : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。