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