ホーム › UI.Shell.PropertiesSystem › PSPropertyBag_ReadStr
PSPropertyBag_ReadStr
関数プロパティバッグから文字列をバッファへ読み取る。
シグネチャ
// PROPSYS.dll
#include <windows.h>
HRESULT PSPropertyBag_ReadStr(
IPropertyBag* propBag,
LPCWSTR propName,
LPWSTR value,
INT characterCount
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| propBag | IPropertyBag* | in | 値を読み出す対象のプロパティバッグ。 |
| propName | LPCWSTR | in | 読み出すプロパティの名前。 |
| value | LPWSTR | out | 読み出した文字列を受け取る出力バッファ。 |
| characterCount | INT | in | valueバッファのサイズ(文字数)。終端NULを含む。 |
戻り値の型: 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 方式にも切替可。#uselib "PROPSYS.dll" #cfunc global PSPropertyBag_ReadStr "PSPropertyBag_ReadStr" sptr, wstr, sptr, int ; res = PSPropertyBag_ReadStr(propBag, propName, varptr(value), characterCount) ; propBag : IPropertyBag* -> "sptr" ; propName : LPCWSTR -> "wstr" ; value : LPWSTR out -> "sptr" ; characterCount : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; HRESULT PSPropertyBag_ReadStr(IPropertyBag* propBag, LPCWSTR propName, LPWSTR value, INT characterCount) #uselib "PROPSYS.dll" #cfunc global PSPropertyBag_ReadStr "PSPropertyBag_ReadStr" intptr, wstr, intptr, int ; res = PSPropertyBag_ReadStr(propBag, propName, varptr(value), characterCount) ; propBag : IPropertyBag* -> "intptr" ; propName : LPCWSTR -> "wstr" ; value : LPWSTR out -> "intptr" ; characterCount : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // HRESULTfunction 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)。const std = @import("std");
extern "propsys" fn PSPropertyBag_ReadStr(
propBag: ?*anyopaque, // IPropertyBag*
propName: [*c]const u16, // LPCWSTR
value: [*c]u16, // LPWSTR out
characterCount: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc PSPropertyBag_ReadStr(
propBag: pointer, # IPropertyBag*
propName: WideCString, # LPCWSTR
value: ptr uint16, # LPWSTR out
characterCount: int32 # INT
): int32 {.importc: "PSPropertyBag_ReadStr", stdcall, dynlib: "PROPSYS.dll".}pragma(lib, "propsys");
extern(Windows)
int PSPropertyBag_ReadStr(
void* propBag, // IPropertyBag*
const(wchar)* propName, // LPCWSTR
wchar* value, // LPWSTR out
int characterCount // INT
);ccall((:PSPropertyBag_ReadStr, "PROPSYS.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, Ptr{UInt16}, Int32),
propBag, propName, value, characterCount)
# propBag : IPropertyBag* -> Ptr{Cvoid}
# propName : LPCWSTR -> Cwstring
# value : LPWSTR out -> Ptr{UInt16}
# characterCount : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PSPropertyBag_ReadStr(
void* propBag,
const uint16_t* propName,
uint16_t* value,
int32_t characterCount);
]]
local propsys = ffi.load("propsys")
-- propsys.PSPropertyBag_ReadStr(propBag, propName, value, characterCount)
-- propBag : IPropertyBag*
-- propName : LPCWSTR
-- value : LPWSTR out
-- characterCount : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('PROPSYS.dll');
const PSPropertyBag_ReadStr = lib.func('__stdcall', 'PSPropertyBag_ReadStr', 'int32_t', ['void *', 'str16', 'uint16_t *', 'int32_t']);
// PSPropertyBag_ReadStr(propBag, propName, value, characterCount)
// propBag : IPropertyBag* -> 'void *'
// propName : LPCWSTR -> 'str16'
// value : LPWSTR out -> 'uint16_t *'
// characterCount : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("PROPSYS.dll", {
PSPropertyBag_ReadStr: { parameters: ["pointer", "buffer", "buffer", "i32"], result: "i32" },
});
// lib.symbols.PSPropertyBag_ReadStr(propBag, propName, value, characterCount)
// propBag : IPropertyBag* -> "pointer"
// propName : LPCWSTR -> "buffer"
// value : LPWSTR out -> "buffer"
// characterCount : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PSPropertyBag_ReadStr(
void* propBag,
const uint16_t* propName,
uint16_t* value,
int32_t characterCount);
C, "PROPSYS.dll");
// $ffi->PSPropertyBag_ReadStr(propBag, propName, value, characterCount);
// propBag : IPropertyBag*
// propName : LPCWSTR
// value : LPWSTR out
// characterCount : INT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Propsys extends StdCallLibrary {
Propsys INSTANCE = Native.load("propsys", Propsys.class);
int PSPropertyBag_ReadStr(
Pointer propBag, // IPropertyBag*
WString propName, // LPCWSTR
char[] value, // LPWSTR out
int characterCount // INT
);
}@[Link("propsys")]
lib LibPROPSYS
fun PSPropertyBag_ReadStr = PSPropertyBag_ReadStr(
propBag : Void*, # IPropertyBag*
propName : UInt16*, # LPCWSTR
value : UInt16*, # LPWSTR out
characterCount : Int32 # INT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PSPropertyBag_ReadStrNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Int32);
typedef PSPropertyBag_ReadStrDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int);
final PSPropertyBag_ReadStr = DynamicLibrary.open('PROPSYS.dll')
.lookupFunction<PSPropertyBag_ReadStrNative, PSPropertyBag_ReadStrDart>('PSPropertyBag_ReadStr');
// propBag : IPropertyBag* -> Pointer<Void>
// propName : LPCWSTR -> Pointer<Utf16>
// value : LPWSTR out -> Pointer<Utf16>
// characterCount : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PSPropertyBag_ReadStr(
propBag: Pointer; // IPropertyBag*
propName: PWideChar; // LPCWSTR
value: PWideChar; // LPWSTR out
characterCount: Integer // INT
): Integer; stdcall;
external 'PROPSYS.dll' name 'PSPropertyBag_ReadStr';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PSPropertyBag_ReadStr"
c_PSPropertyBag_ReadStr :: Ptr () -> CWString -> CWString -> Int32 -> IO Int32
-- propBag : IPropertyBag* -> Ptr ()
-- propName : LPCWSTR -> CWString
-- value : LPWSTR out -> CWString
-- characterCount : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pspropertybag_readstr =
foreign "PSPropertyBag_ReadStr"
((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* propBag : IPropertyBag* -> (ptr void) *)
(* propName : LPCWSTR -> (ptr uint16_t) *)
(* value : LPWSTR out -> (ptr uint16_t) *)
(* characterCount : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library propsys (t "PROPSYS.dll"))
(cffi:use-foreign-library propsys)
(cffi:defcfun ("PSPropertyBag_ReadStr" psproperty-bag-read-str :convention :stdcall) :int32
(prop-bag :pointer) ; IPropertyBag*
(prop-name (:string :encoding :utf-16le)) ; LPCWSTR
(value :pointer) ; LPWSTR out
(character-count :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PSPropertyBag_ReadStr = Win32::API::More->new('PROPSYS',
'int PSPropertyBag_ReadStr(LPVOID propBag, LPCWSTR propName, LPWSTR value, int characterCount)');
# my $ret = $PSPropertyBag_ReadStr->Call($propBag, $propName, $value, $characterCount);
# propBag : IPropertyBag* -> LPVOID
# propName : LPCWSTR -> LPCWSTR
# value : LPWSTR out -> LPWSTR
# characterCount : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型