Win32 API 日本語リファレンス
ホームSystem.Ole › OleCreateLinkToFile

OleCreateLinkToFile

関数
指定ファイルへリンクするOLEオブジェクトを作成する。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT OleCreateLinkToFile(
    LPCWSTR lpszFileName,
    const GUID* riid,
    DWORD renderopt,
    FORMATETC* lpFormatEtc,
    IOleClientSite* pClientSite,
    IStorage* pStg,
    void** ppvObj
);

パラメーター

名前方向
lpszFileNameLPCWSTRin
riidGUID*in
renderoptDWORDin
lpFormatEtcFORMATETC*in
pClientSiteIOleClientSite*in
pStgIStorage*in
ppvObjvoid**out

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

OleCreateLinkToFile = ctypes.windll.ole32.OleCreateLinkToFile
OleCreateLinkToFile.restype = ctypes.c_int
OleCreateLinkToFile.argtypes = [
    wintypes.LPCWSTR,  # lpszFileName : LPCWSTR
    ctypes.c_void_p,  # riid : GUID*
    wintypes.DWORD,  # renderopt : DWORD
    ctypes.c_void_p,  # lpFormatEtc : FORMATETC*
    ctypes.c_void_p,  # pClientSite : IOleClientSite*
    ctypes.c_void_p,  # pStg : IStorage*
    ctypes.c_void_p,  # ppvObj : void** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procOleCreateLinkToFile = ole32.NewProc("OleCreateLinkToFile")
)

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