ホーム › UI.Shell.PropertiesSystem › PSPropertyBag_ReadStrAlloc
PSPropertyBag_ReadStrAlloc
関数プロパティバッグから文字列を読み取りバッファを確保する。
シグネチャ
// PROPSYS.dll
#include <windows.h>
HRESULT PSPropertyBag_ReadStrAlloc(
IPropertyBag* propBag,
LPCWSTR propName,
LPWSTR* value
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| propBag | IPropertyBag* | in | 値を読み出す対象のプロパティバッグ。 |
| propName | LPCWSTR | in | 読み出すプロパティの名前。 |
| value | LPWSTR* | out | 読み出した文字列を受け取る出力先。CoTaskMemFreeで解放する。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// PROPSYS.dll
#include <windows.h>
HRESULT PSPropertyBag_ReadStrAlloc(
IPropertyBag* propBag,
LPCWSTR propName,
LPWSTR* value
);[DllImport("PROPSYS.dll", ExactSpelling = true)]
static extern int PSPropertyBag_ReadStrAlloc(
IntPtr propBag, // IPropertyBag*
[MarshalAs(UnmanagedType.LPWStr)] string propName, // LPCWSTR
IntPtr value // LPWSTR* out
);<DllImport("PROPSYS.dll", ExactSpelling:=True)>
Public Shared Function PSPropertyBag_ReadStrAlloc(
propBag As IntPtr, ' IPropertyBag*
<MarshalAs(UnmanagedType.LPWStr)> propName As String, ' LPCWSTR
value As IntPtr ' LPWSTR* out
) As Integer
End Function' propBag : IPropertyBag*
' propName : LPCWSTR
' value : LPWSTR* out
Declare PtrSafe Function PSPropertyBag_ReadStrAlloc Lib "propsys" ( _
ByVal propBag As LongPtr, _
ByVal propName As LongPtr, _
ByVal value As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PSPropertyBag_ReadStrAlloc = ctypes.windll.propsys.PSPropertyBag_ReadStrAlloc
PSPropertyBag_ReadStrAlloc.restype = ctypes.c_int
PSPropertyBag_ReadStrAlloc.argtypes = [
ctypes.c_void_p, # propBag : IPropertyBag*
wintypes.LPCWSTR, # propName : LPCWSTR
ctypes.c_void_p, # value : LPWSTR* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('PROPSYS.dll')
PSPropertyBag_ReadStrAlloc = Fiddle::Function.new(
lib['PSPropertyBag_ReadStrAlloc'],
[
Fiddle::TYPE_VOIDP, # propBag : IPropertyBag*
Fiddle::TYPE_VOIDP, # propName : LPCWSTR
Fiddle::TYPE_VOIDP, # value : LPWSTR* out
],
Fiddle::TYPE_INT)#[link(name = "propsys")]
extern "system" {
fn PSPropertyBag_ReadStrAlloc(
propBag: *mut core::ffi::c_void, // IPropertyBag*
propName: *const u16, // LPCWSTR
value: *mut *mut u16 // LPWSTR* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("PROPSYS.dll")]
public static extern int PSPropertyBag_ReadStrAlloc(IntPtr propBag, [MarshalAs(UnmanagedType.LPWStr)] string propName, IntPtr value);
"@
$api = Add-Type -MemberDefinition $sig -Name 'PROPSYS_PSPropertyBag_ReadStrAlloc' -Namespace Win32 -PassThru
# $api::PSPropertyBag_ReadStrAlloc(propBag, propName, value)#uselib "PROPSYS.dll"
#func global PSPropertyBag_ReadStrAlloc "PSPropertyBag_ReadStrAlloc" sptr, sptr, sptr
; PSPropertyBag_ReadStrAlloc propBag, propName, varptr(value) ; 戻り値は stat
; propBag : IPropertyBag* -> "sptr"
; propName : LPCWSTR -> "sptr"
; value : LPWSTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "PROPSYS.dll" #cfunc global PSPropertyBag_ReadStrAlloc "PSPropertyBag_ReadStrAlloc" sptr, wstr, var ; res = PSPropertyBag_ReadStrAlloc(propBag, propName, value) ; propBag : IPropertyBag* -> "sptr" ; propName : LPCWSTR -> "wstr" ; value : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "PROPSYS.dll" #cfunc global PSPropertyBag_ReadStrAlloc "PSPropertyBag_ReadStrAlloc" sptr, wstr, sptr ; res = PSPropertyBag_ReadStrAlloc(propBag, propName, varptr(value)) ; propBag : IPropertyBag* -> "sptr" ; propName : LPCWSTR -> "wstr" ; value : LPWSTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT PSPropertyBag_ReadStrAlloc(IPropertyBag* propBag, LPCWSTR propName, LPWSTR* value) #uselib "PROPSYS.dll" #cfunc global PSPropertyBag_ReadStrAlloc "PSPropertyBag_ReadStrAlloc" intptr, wstr, var ; res = PSPropertyBag_ReadStrAlloc(propBag, propName, value) ; propBag : IPropertyBag* -> "intptr" ; propName : LPCWSTR -> "wstr" ; value : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT PSPropertyBag_ReadStrAlloc(IPropertyBag* propBag, LPCWSTR propName, LPWSTR* value) #uselib "PROPSYS.dll" #cfunc global PSPropertyBag_ReadStrAlloc "PSPropertyBag_ReadStrAlloc" intptr, wstr, intptr ; res = PSPropertyBag_ReadStrAlloc(propBag, propName, varptr(value)) ; propBag : IPropertyBag* -> "intptr" ; propName : LPCWSTR -> "wstr" ; value : LPWSTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
propsys = windows.NewLazySystemDLL("PROPSYS.dll")
procPSPropertyBag_ReadStrAlloc = propsys.NewProc("PSPropertyBag_ReadStrAlloc")
)
// propBag (IPropertyBag*), propName (LPCWSTR), value (LPWSTR* out)
r1, _, err := procPSPropertyBag_ReadStrAlloc.Call(
uintptr(propBag),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(propName))),
uintptr(value),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction PSPropertyBag_ReadStrAlloc(
propBag: Pointer; // IPropertyBag*
propName: PWideChar; // LPCWSTR
value: PPWideChar // LPWSTR* out
): Integer; stdcall;
external 'PROPSYS.dll' name 'PSPropertyBag_ReadStrAlloc';result := DllCall("PROPSYS\PSPropertyBag_ReadStrAlloc"
, "Ptr", propBag ; IPropertyBag*
, "WStr", propName ; LPCWSTR
, "Ptr", value ; LPWSTR* out
, "Int") ; return: HRESULT●PSPropertyBag_ReadStrAlloc(propBag, propName, value) = DLL("PROPSYS.dll", "int PSPropertyBag_ReadStrAlloc(void*, char*, void*)")
# 呼び出し: PSPropertyBag_ReadStrAlloc(propBag, propName, value)
# propBag : IPropertyBag* -> "void*"
# propName : LPCWSTR -> "char*"
# value : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。