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

PSPropertyKeyFromString

関数
文字列をプロパティキー構造体に変換する。
DLLPROPSYS.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT PSPropertyKeyFromString(
    LPCWSTR pszString,
    PROPERTYKEY* pkey
);

パラメーター

名前方向
pszStringLPCWSTRin
pkeyPROPERTYKEY*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

PSPropertyKeyFromString = ctypes.windll.propsys.PSPropertyKeyFromString
PSPropertyKeyFromString.restype = ctypes.c_int
PSPropertyKeyFromString.argtypes = [
    wintypes.LPCWSTR,  # pszString : LPCWSTR
    ctypes.c_void_p,  # pkey : PROPERTYKEY* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	propsys = windows.NewLazySystemDLL("PROPSYS.dll")
	procPSPropertyKeyFromString = propsys.NewProc("PSPropertyKeyFromString")
)

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