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

SHUnicodeToUnicode

関数
Unicode文字列をバッファ長を考慮して複製する。
DLLSHLWAPI.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll
#include <windows.h>

INT SHUnicodeToUnicode(
    LPCWSTR pwzSrc,
    LPWSTR pwzDst,
    INT cwchBuf
);

パラメーター

名前方向
pwzSrcLPCWSTRin
pwzDstLPWSTRout
cwchBufINTin

戻り値の型: INT

各言語での呼び出し定義

// SHLWAPI.dll
#include <windows.h>

INT SHUnicodeToUnicode(
    LPCWSTR pwzSrc,
    LPWSTR pwzDst,
    INT cwchBuf
);
[DllImport("SHLWAPI.dll", ExactSpelling = true)]
static extern int SHUnicodeToUnicode(
    [MarshalAs(UnmanagedType.LPWStr)] string pwzSrc,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pwzDst,   // LPWSTR out
    int cwchBuf   // INT
);
<DllImport("SHLWAPI.dll", ExactSpelling:=True)>
Public Shared Function SHUnicodeToUnicode(
    <MarshalAs(UnmanagedType.LPWStr)> pwzSrc As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pwzDst As System.Text.StringBuilder,   ' LPWSTR out
    cwchBuf As Integer   ' INT
) As Integer
End Function
' pwzSrc : LPCWSTR
' pwzDst : LPWSTR out
' cwchBuf : INT
Declare PtrSafe Function SHUnicodeToUnicode Lib "shlwapi" ( _
    ByVal pwzSrc As LongPtr, _
    ByVal pwzDst As LongPtr, _
    ByVal cwchBuf As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHUnicodeToUnicode = ctypes.windll.shlwapi.SHUnicodeToUnicode
SHUnicodeToUnicode.restype = ctypes.c_int
SHUnicodeToUnicode.argtypes = [
    wintypes.LPCWSTR,  # pwzSrc : LPCWSTR
    wintypes.LPWSTR,  # pwzDst : LPWSTR out
    ctypes.c_int,  # cwchBuf : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
SHUnicodeToUnicode = Fiddle::Function.new(
  lib['SHUnicodeToUnicode'],
  [
    Fiddle::TYPE_VOIDP,  # pwzSrc : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pwzDst : LPWSTR out
    Fiddle::TYPE_INT,  # cwchBuf : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn SHUnicodeToUnicode(
        pwzSrc: *const u16,  // LPCWSTR
        pwzDst: *mut u16,  // LPWSTR out
        cwchBuf: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll")]
public static extern int SHUnicodeToUnicode([MarshalAs(UnmanagedType.LPWStr)] string pwzSrc, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pwzDst, int cwchBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHUnicodeToUnicode' -Namespace Win32 -PassThru
# $api::SHUnicodeToUnicode(pwzSrc, pwzDst, cwchBuf)
#uselib "SHLWAPI.dll"
#func global SHUnicodeToUnicode "SHUnicodeToUnicode" sptr, sptr, sptr
; SHUnicodeToUnicode pwzSrc, varptr(pwzDst), cwchBuf   ; 戻り値は stat
; pwzSrc : LPCWSTR -> "sptr"
; pwzDst : LPWSTR out -> "sptr"
; cwchBuf : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHLWAPI.dll"
#cfunc global SHUnicodeToUnicode "SHUnicodeToUnicode" wstr, var, int
; res = SHUnicodeToUnicode(pwzSrc, pwzDst, cwchBuf)
; pwzSrc : LPCWSTR -> "wstr"
; pwzDst : LPWSTR out -> "var"
; cwchBuf : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT SHUnicodeToUnicode(LPCWSTR pwzSrc, LPWSTR pwzDst, INT cwchBuf)
#uselib "SHLWAPI.dll"
#cfunc global SHUnicodeToUnicode "SHUnicodeToUnicode" wstr, var, int
; res = SHUnicodeToUnicode(pwzSrc, pwzDst, cwchBuf)
; pwzSrc : LPCWSTR -> "wstr"
; pwzDst : LPWSTR out -> "var"
; cwchBuf : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHUnicodeToUnicode = shlwapi.NewProc("SHUnicodeToUnicode")
)

// pwzSrc (LPCWSTR), pwzDst (LPWSTR out), cwchBuf (INT)
r1, _, err := procSHUnicodeToUnicode.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwzSrc))),
	uintptr(pwzDst),
	uintptr(cwchBuf),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function SHUnicodeToUnicode(
  pwzSrc: PWideChar;   // LPCWSTR
  pwzDst: PWideChar;   // LPWSTR out
  cwchBuf: Integer   // INT
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'SHUnicodeToUnicode';
result := DllCall("SHLWAPI\SHUnicodeToUnicode"
    , "WStr", pwzSrc   ; LPCWSTR
    , "Ptr", pwzDst   ; LPWSTR out
    , "Int", cwchBuf   ; INT
    , "Int")   ; return: INT
●SHUnicodeToUnicode(pwzSrc, pwzDst, cwchBuf) = DLL("SHLWAPI.dll", "int SHUnicodeToUnicode(char*, char*, int)")
# 呼び出し: SHUnicodeToUnicode(pwzSrc, pwzDst, cwchBuf)
# pwzSrc : LPCWSTR -> "char*"
# pwzDst : LPWSTR out -> "char*"
# cwchBuf : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。