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

PSPropertyBag_ReadStr

関数
プロパティバッグから文字列をバッファへ読み取る。
DLLPROPSYS.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT PSPropertyBag_ReadStr(
    IPropertyBag* propBag,
    LPCWSTR propName,
    LPWSTR value,
    INT characterCount
);

パラメーター

名前方向
propBagIPropertyBag*in
propNameLPCWSTRin
valueLPWSTRout
characterCountINTin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT PSPropertyBag_ReadStr(
    IPropertyBag* propBag,
    LPCWSTR propName,
    LPWSTR value,
    INT characterCount
);
[DllImport("PROPSYS.dll", ExactSpelling = true)]
static extern int PSPropertyBag_ReadStr(
    IntPtr propBag,   // IPropertyBag*
    [MarshalAs(UnmanagedType.LPWStr)] string propName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder value,   // LPWSTR out
    int characterCount   // INT
);
<DllImport("PROPSYS.dll", ExactSpelling:=True)>
Public Shared Function PSPropertyBag_ReadStr(
    propBag As IntPtr,   ' IPropertyBag*
    <MarshalAs(UnmanagedType.LPWStr)> propName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> value As System.Text.StringBuilder,   ' LPWSTR out
    characterCount As Integer   ' INT
) As Integer
End Function
' propBag : IPropertyBag*
' propName : LPCWSTR
' value : LPWSTR out
' characterCount : INT
Declare PtrSafe Function PSPropertyBag_ReadStr Lib "propsys" ( _
    ByVal propBag As LongPtr, _
    ByVal propName As LongPtr, _
    ByVal value As LongPtr, _
    ByVal characterCount As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PSPropertyBag_ReadStr = ctypes.windll.propsys.PSPropertyBag_ReadStr
PSPropertyBag_ReadStr.restype = ctypes.c_int
PSPropertyBag_ReadStr.argtypes = [
    ctypes.c_void_p,  # propBag : IPropertyBag*
    wintypes.LPCWSTR,  # propName : LPCWSTR
    wintypes.LPWSTR,  # value : LPWSTR out
    ctypes.c_int,  # characterCount : INT
]
require 'fiddle'
require 'fiddle/import'

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

var (
	propsys = windows.NewLazySystemDLL("PROPSYS.dll")
	procPSPropertyBag_ReadStr = propsys.NewProc("PSPropertyBag_ReadStr")
)

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