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

StgMakeUniqueName

関数
ストレージ内で一意な名前のサブオブジェクトを生成する。
DLLSHELL32.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT StgMakeUniqueName(
    IStorage* pstgParent,
    LPCWSTR pszFileSpec,
    DWORD grfMode,
    const GUID* riid,
    void** ppv
);

パラメーター

名前方向
pstgParentIStorage*in
pszFileSpecLPCWSTRin
grfModeDWORDin
riidGUID*in
ppvvoid**out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT StgMakeUniqueName(
    IStorage* pstgParent,
    LPCWSTR pszFileSpec,
    DWORD grfMode,
    const GUID* riid,
    void** ppv
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int StgMakeUniqueName(
    IntPtr pstgParent,   // IStorage*
    [MarshalAs(UnmanagedType.LPWStr)] string pszFileSpec,   // LPCWSTR
    uint grfMode,   // DWORD
    ref Guid riid,   // GUID*
    IntPtr ppv   // void** out
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function StgMakeUniqueName(
    pstgParent As IntPtr,   ' IStorage*
    <MarshalAs(UnmanagedType.LPWStr)> pszFileSpec As String,   ' LPCWSTR
    grfMode As UInteger,   ' DWORD
    ByRef riid As Guid,   ' GUID*
    ppv As IntPtr   ' void** out
) As Integer
End Function
' pstgParent : IStorage*
' pszFileSpec : LPCWSTR
' grfMode : DWORD
' riid : GUID*
' ppv : void** out
Declare PtrSafe Function StgMakeUniqueName Lib "shell32" ( _
    ByVal pstgParent As LongPtr, _
    ByVal pszFileSpec As LongPtr, _
    ByVal grfMode As Long, _
    ByVal riid As LongPtr, _
    ByVal ppv As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

StgMakeUniqueName = ctypes.windll.shell32.StgMakeUniqueName
StgMakeUniqueName.restype = ctypes.c_int
StgMakeUniqueName.argtypes = [
    ctypes.c_void_p,  # pstgParent : IStorage*
    wintypes.LPCWSTR,  # pszFileSpec : LPCWSTR
    wintypes.DWORD,  # grfMode : DWORD
    ctypes.c_void_p,  # riid : GUID*
    ctypes.c_void_p,  # ppv : void** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procStgMakeUniqueName = shell32.NewProc("StgMakeUniqueName")
)

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