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

StrNCatW

関数
指定最大長まで文字列を連結する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

LPWSTR StrNCatW(
    LPWSTR psz1,
    LPCWSTR psz2,
    INT cchMax
);

パラメーター

名前方向
psz1LPWSTRinout
psz2LPCWSTRin
cchMaxINTin

戻り値の型: LPWSTR

各言語での呼び出し定義

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

LPWSTR StrNCatW(
    LPWSTR psz1,
    LPCWSTR psz2,
    INT cchMax
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr StrNCatW(
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder psz1,   // LPWSTR in/out
    [MarshalAs(UnmanagedType.LPWStr)] string psz2,   // LPCWSTR
    int cchMax   // INT
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function StrNCatW(
    <MarshalAs(UnmanagedType.LPWStr)> psz1 As System.Text.StringBuilder,   ' LPWSTR in/out
    <MarshalAs(UnmanagedType.LPWStr)> psz2 As String,   ' LPCWSTR
    cchMax As Integer   ' INT
) As IntPtr
End Function
' psz1 : LPWSTR in/out
' psz2 : LPCWSTR
' cchMax : INT
Declare PtrSafe Function StrNCatW Lib "shlwapi" ( _
    ByVal psz1 As LongPtr, _
    ByVal psz2 As LongPtr, _
    ByVal cchMax 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

StrNCatW = ctypes.windll.shlwapi.StrNCatW
StrNCatW.restype = wintypes.LPWSTR
StrNCatW.argtypes = [
    wintypes.LPWSTR,  # psz1 : LPWSTR in/out
    wintypes.LPCWSTR,  # psz2 : LPCWSTR
    ctypes.c_int,  # cchMax : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
StrNCatW = Fiddle::Function.new(
  lib['StrNCatW'],
  [
    Fiddle::TYPE_VOIDP,  # psz1 : LPWSTR in/out
    Fiddle::TYPE_VOIDP,  # psz2 : LPCWSTR
    Fiddle::TYPE_INT,  # cchMax : INT
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shlwapi")]
extern "system" {
    fn StrNCatW(
        psz1: *mut u16,  // LPWSTR in/out
        psz2: *const u16,  // LPCWSTR
        cchMax: 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 StrNCatW([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder psz1, [MarshalAs(UnmanagedType.LPWStr)] string psz2, int cchMax);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrNCatW' -Namespace Win32 -PassThru
# $api::StrNCatW(psz1, psz2, cchMax)
#uselib "SHLWAPI.dll"
#func global StrNCatW "StrNCatW" wptr, wptr, wptr
; StrNCatW varptr(psz1), psz2, cchMax   ; 戻り値は stat
; psz1 : LPWSTR in/out -> "wptr"
; psz2 : LPCWSTR -> "wptr"
; cchMax : INT -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHLWAPI.dll"
#cfunc global StrNCatW "StrNCatW" var, wstr, int
; res = StrNCatW(psz1, psz2, cchMax)
; psz1 : LPWSTR in/out -> "var"
; psz2 : LPCWSTR -> "wstr"
; cchMax : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; LPWSTR StrNCatW(LPWSTR psz1, LPCWSTR psz2, INT cchMax)
#uselib "SHLWAPI.dll"
#cfunc global StrNCatW "StrNCatW" var, wstr, int
; res = StrNCatW(psz1, psz2, cchMax)
; psz1 : LPWSTR in/out -> "var"
; psz2 : LPCWSTR -> "wstr"
; cchMax : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procStrNCatW = shlwapi.NewProc("StrNCatW")
)

// psz1 (LPWSTR in/out), psz2 (LPCWSTR), cchMax (INT)
r1, _, err := procStrNCatW.Call(
	uintptr(psz1),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(psz2))),
	uintptr(cchMax),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LPWSTR
function StrNCatW(
  psz1: PWideChar;   // LPWSTR in/out
  psz2: PWideChar;   // LPCWSTR
  cchMax: Integer   // INT
): PWideChar; stdcall;
  external 'SHLWAPI.dll' name 'StrNCatW';
result := DllCall("SHLWAPI\StrNCatW"
    , "Ptr", psz1   ; LPWSTR in/out
    , "WStr", psz2   ; LPCWSTR
    , "Int", cchMax   ; INT
    , "Ptr")   ; return: LPWSTR
●StrNCatW(psz1, psz2, cchMax) = DLL("SHLWAPI.dll", "char* StrNCatW(char*, char*, int)")
# 呼び出し: StrNCatW(psz1, psz2, cchMax)
# psz1 : LPWSTR in/out -> "char*"
# psz2 : LPCWSTR -> "char*"
# cchMax : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。