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

SHStrDupA

関数
文字列を複製してUnicode文字列として返す。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

HRESULT SHStrDupA(
    LPCSTR psz,
    LPWSTR* ppwsz
);

パラメーター

名前方向
pszLPCSTRin
ppwszLPWSTR*out

戻り値の型: HRESULT

各言語での呼び出し定義

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

HRESULT SHStrDupA(
    LPCSTR psz,
    LPWSTR* ppwsz
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int SHStrDupA(
    [MarshalAs(UnmanagedType.LPStr)] string psz,   // LPCSTR
    IntPtr ppwsz   // LPWSTR* out
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SHStrDupA(
    <MarshalAs(UnmanagedType.LPStr)> psz As String,   ' LPCSTR
    ppwsz As IntPtr   ' LPWSTR* out
) As Integer
End Function
' psz : LPCSTR
' ppwsz : LPWSTR* out
Declare PtrSafe Function SHStrDupA Lib "shlwapi" ( _
    ByVal psz As String, _
    ByVal ppwsz As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHStrDupA = ctypes.windll.shlwapi.SHStrDupA
SHStrDupA.restype = ctypes.c_int
SHStrDupA.argtypes = [
    wintypes.LPCSTR,  # psz : LPCSTR
    ctypes.c_void_p,  # ppwsz : LPWSTR* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHStrDupA = shlwapi.NewProc("SHStrDupA")
)

// psz (LPCSTR), ppwsz (LPWSTR* out)
r1, _, err := procSHStrDupA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(psz))),
	uintptr(ppwsz),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SHStrDupA(
  psz: PAnsiChar;   // LPCSTR
  ppwsz: PPWideChar   // LPWSTR* out
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'SHStrDupA';
result := DllCall("SHLWAPI\SHStrDupA"
    , "AStr", psz   ; LPCSTR
    , "Ptr", ppwsz   ; LPWSTR* out
    , "Int")   ; return: HRESULT
●SHStrDupA(psz, ppwsz) = DLL("SHLWAPI.dll", "int SHStrDupA(char*, void*)")
# 呼び出し: SHStrDupA(psz, ppwsz)
# psz : LPCSTR -> "char*"
# ppwsz : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。