StrCatBuffW
関数バッファサイズを超えないように文字列を連結する。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
LPWSTR StrCatBuffW(
LPWSTR pszDest,
LPCWSTR pszSrc,
INT cchDestBuffSize
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszDest | LPWSTR | inout |
| pszSrc | LPCWSTR | in |
| cchDestBuffSize | INT | in |
戻り値の型: LPWSTR
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
LPWSTR StrCatBuffW(
LPWSTR pszDest,
LPCWSTR pszSrc,
INT cchDestBuffSize
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr StrCatBuffW(
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszDest, // LPWSTR in/out
[MarshalAs(UnmanagedType.LPWStr)] string pszSrc, // LPCWSTR
int cchDestBuffSize // INT
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function StrCatBuffW(
<MarshalAs(UnmanagedType.LPWStr)> pszDest As System.Text.StringBuilder, ' LPWSTR in/out
<MarshalAs(UnmanagedType.LPWStr)> pszSrc As String, ' LPCWSTR
cchDestBuffSize As Integer ' INT
) As IntPtr
End Function' pszDest : LPWSTR in/out
' pszSrc : LPCWSTR
' cchDestBuffSize : INT
Declare PtrSafe Function StrCatBuffW Lib "shlwapi" ( _
ByVal pszDest As LongPtr, _
ByVal pszSrc As LongPtr, _
ByVal cchDestBuffSize As Long) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
StrCatBuffW = ctypes.windll.shlwapi.StrCatBuffW
StrCatBuffW.restype = wintypes.LPWSTR
StrCatBuffW.argtypes = [
wintypes.LPWSTR, # pszDest : LPWSTR in/out
wintypes.LPCWSTR, # pszSrc : LPCWSTR
ctypes.c_int, # cchDestBuffSize : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
StrCatBuffW = Fiddle::Function.new(
lib['StrCatBuffW'],
[
Fiddle::TYPE_VOIDP, # pszDest : LPWSTR in/out
Fiddle::TYPE_VOIDP, # pszSrc : LPCWSTR
Fiddle::TYPE_INT, # cchDestBuffSize : INT
],
Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shlwapi")]
extern "system" {
fn StrCatBuffW(
pszDest: *mut u16, // LPWSTR in/out
pszSrc: *const u16, // LPCWSTR
cchDestBuffSize: i32 // INT
) -> *mut u16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr StrCatBuffW([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszDest, [MarshalAs(UnmanagedType.LPWStr)] string pszSrc, int cchDestBuffSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrCatBuffW' -Namespace Win32 -PassThru
# $api::StrCatBuffW(pszDest, pszSrc, cchDestBuffSize)#uselib "SHLWAPI.dll"
#func global StrCatBuffW "StrCatBuffW" wptr, wptr, wptr
; StrCatBuffW varptr(pszDest), pszSrc, cchDestBuffSize ; 戻り値は stat
; pszDest : LPWSTR in/out -> "wptr"
; pszSrc : LPCWSTR -> "wptr"
; cchDestBuffSize : INT -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global StrCatBuffW "StrCatBuffW" var, wstr, int ; res = StrCatBuffW(pszDest, pszSrc, cchDestBuffSize) ; pszDest : LPWSTR in/out -> "var" ; pszSrc : LPCWSTR -> "wstr" ; cchDestBuffSize : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global StrCatBuffW "StrCatBuffW" sptr, wstr, int ; res = StrCatBuffW(varptr(pszDest), pszSrc, cchDestBuffSize) ; pszDest : LPWSTR in/out -> "sptr" ; pszSrc : LPCWSTR -> "wstr" ; cchDestBuffSize : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; LPWSTR StrCatBuffW(LPWSTR pszDest, LPCWSTR pszSrc, INT cchDestBuffSize) #uselib "SHLWAPI.dll" #cfunc global StrCatBuffW "StrCatBuffW" var, wstr, int ; res = StrCatBuffW(pszDest, pszSrc, cchDestBuffSize) ; pszDest : LPWSTR in/out -> "var" ; pszSrc : LPCWSTR -> "wstr" ; cchDestBuffSize : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; LPWSTR StrCatBuffW(LPWSTR pszDest, LPCWSTR pszSrc, INT cchDestBuffSize) #uselib "SHLWAPI.dll" #cfunc global StrCatBuffW "StrCatBuffW" intptr, wstr, int ; res = StrCatBuffW(varptr(pszDest), pszSrc, cchDestBuffSize) ; pszDest : LPWSTR in/out -> "intptr" ; pszSrc : LPCWSTR -> "wstr" ; cchDestBuffSize : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procStrCatBuffW = shlwapi.NewProc("StrCatBuffW")
)
// pszDest (LPWSTR in/out), pszSrc (LPCWSTR), cchDestBuffSize (INT)
r1, _, err := procStrCatBuffW.Call(
uintptr(pszDest),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSrc))),
uintptr(cchDestBuffSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // LPWSTRfunction StrCatBuffW(
pszDest: PWideChar; // LPWSTR in/out
pszSrc: PWideChar; // LPCWSTR
cchDestBuffSize: Integer // INT
): PWideChar; stdcall;
external 'SHLWAPI.dll' name 'StrCatBuffW';result := DllCall("SHLWAPI\StrCatBuffW"
, "Ptr", pszDest ; LPWSTR in/out
, "WStr", pszSrc ; LPCWSTR
, "Int", cchDestBuffSize ; INT
, "Ptr") ; return: LPWSTR●StrCatBuffW(pszDest, pszSrc, cchDestBuffSize) = DLL("SHLWAPI.dll", "char* StrCatBuffW(char*, char*, int)")
# 呼び出し: StrCatBuffW(pszDest, pszSrc, cchDestBuffSize)
# pszDest : LPWSTR in/out -> "char*"
# pszSrc : LPCWSTR -> "char*"
# cchDestBuffSize : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。