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

SHAddDefaultPropertiesByExt

関数
拡張子に基づく既定プロパティをストアに追加する。
DLLSHELL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT SHAddDefaultPropertiesByExt(
    LPCWSTR pszExt,
    IPropertyStore* pPropStore
);

パラメーター

名前方向
pszExtLPCWSTRin
pPropStoreIPropertyStore*in

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

SHAddDefaultPropertiesByExt = ctypes.windll.shell32.SHAddDefaultPropertiesByExt
SHAddDefaultPropertiesByExt.restype = ctypes.c_int
SHAddDefaultPropertiesByExt.argtypes = [
    wintypes.LPCWSTR,  # pszExt : LPCWSTR
    ctypes.c_void_p,  # pPropStore : IPropertyStore*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
SHAddDefaultPropertiesByExt = Fiddle::Function.new(
  lib['SHAddDefaultPropertiesByExt'],
  [
    Fiddle::TYPE_VOIDP,  # pszExt : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pPropStore : IPropertyStore*
  ],
  Fiddle::TYPE_INT)
#[link(name = "shell32")]
extern "system" {
    fn SHAddDefaultPropertiesByExt(
        pszExt: *const u16,  // LPCWSTR
        pPropStore: *mut core::ffi::c_void  // IPropertyStore*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll")]
public static extern int SHAddDefaultPropertiesByExt([MarshalAs(UnmanagedType.LPWStr)] string pszExt, IntPtr pPropStore);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHAddDefaultPropertiesByExt' -Namespace Win32 -PassThru
# $api::SHAddDefaultPropertiesByExt(pszExt, pPropStore)
#uselib "SHELL32.dll"
#func global SHAddDefaultPropertiesByExt "SHAddDefaultPropertiesByExt" sptr, sptr
; SHAddDefaultPropertiesByExt pszExt, pPropStore   ; 戻り値は stat
; pszExt : LPCWSTR -> "sptr"
; pPropStore : IPropertyStore* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHELL32.dll"
#cfunc global SHAddDefaultPropertiesByExt "SHAddDefaultPropertiesByExt" wstr, sptr
; res = SHAddDefaultPropertiesByExt(pszExt, pPropStore)
; pszExt : LPCWSTR -> "wstr"
; pPropStore : IPropertyStore* -> "sptr"
; HRESULT SHAddDefaultPropertiesByExt(LPCWSTR pszExt, IPropertyStore* pPropStore)
#uselib "SHELL32.dll"
#cfunc global SHAddDefaultPropertiesByExt "SHAddDefaultPropertiesByExt" wstr, intptr
; res = SHAddDefaultPropertiesByExt(pszExt, pPropStore)
; pszExt : LPCWSTR -> "wstr"
; pPropStore : IPropertyStore* -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHAddDefaultPropertiesByExt = shell32.NewProc("SHAddDefaultPropertiesByExt")
)

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