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