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