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

SafeRef

関数
オブジェクトへのセーフ参照ポインターを取得する。
DLLcomsvcs.dll呼出規約cdecl対応OSWindows 2000 以降

シグネチャ

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

void* SafeRef(
    const GUID* rid,
    IUnknown* pUnk
);

パラメーター

名前方向
ridGUID*in
pUnkIUnknown*in

戻り値の型: void*

各言語での呼び出し定義

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

void* SafeRef(
    const GUID* rid,
    IUnknown* pUnk
);
[DllImport("comsvcs.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr SafeRef(
    ref Guid rid,   // GUID*
    IntPtr pUnk   // IUnknown*
);
<DllImport("comsvcs.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function SafeRef(
    ByRef rid As Guid,   ' GUID*
    pUnk As IntPtr   ' IUnknown*
) As IntPtr
End Function
' rid : GUID*
' pUnk : IUnknown*
Declare PtrSafe Function SafeRef Lib "comsvcs" ( _
    ByVal rid As LongPtr, _
    ByVal pUnk As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SafeRef = ctypes.cdll.comsvcs.SafeRef
SafeRef.restype = ctypes.c_void_p
SafeRef.argtypes = [
    ctypes.c_void_p,  # rid : GUID*
    ctypes.c_void_p,  # pUnk : IUnknown*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('comsvcs.dll')
SafeRef = Fiddle::Function.new(
  lib['SafeRef'],
  [
    Fiddle::TYPE_VOIDP,  # rid : GUID*
    Fiddle::TYPE_VOIDP,  # pUnk : IUnknown*
  ],
  Fiddle::TYPE_VOIDP, Fiddle::Function::CDECL)
#[link(name = "comsvcs")]
extern "C" {
    fn SafeRef(
        rid: *const GUID,  // GUID*
        pUnk: *mut core::ffi::c_void  // IUnknown*
    ) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("comsvcs.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr SafeRef(ref Guid rid, IntPtr pUnk);
"@
$api = Add-Type -MemberDefinition $sig -Name 'comsvcs_SafeRef' -Namespace Win32 -PassThru
# $api::SafeRef(rid, pUnk)
#uselib "comsvcs.dll"
#func global SafeRef "SafeRef" sptr, sptr
; SafeRef varptr(rid), pUnk   ; 戻り値は stat
; rid : GUID* -> "sptr"
; pUnk : IUnknown* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "comsvcs.dll"
#cfunc global SafeRef "SafeRef" var, sptr
; res = SafeRef(rid, pUnk)
; rid : GUID* -> "var"
; pUnk : IUnknown* -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void* SafeRef(GUID* rid, IUnknown* pUnk)
#uselib "comsvcs.dll"
#cfunc global SafeRef "SafeRef" var, intptr
; res = SafeRef(rid, pUnk)
; rid : GUID* -> "var"
; pUnk : IUnknown* -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	comsvcs = windows.NewLazySystemDLL("comsvcs.dll")
	procSafeRef = comsvcs.NewProc("SafeRef")
)

// rid (GUID*), pUnk (IUnknown*)
r1, _, err := procSafeRef.Call(
	uintptr(rid),
	uintptr(pUnk),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void*
function SafeRef(
  rid: PGUID;   // GUID*
  pUnk: Pointer   // IUnknown*
): Pointer; cdecl;
  external 'comsvcs.dll' name 'SafeRef';
result := DllCall("comsvcs\SafeRef"
    , "Ptr", rid   ; GUID*
    , "Ptr", pUnk   ; IUnknown*
    , "Cdecl Ptr")   ; return: void*
●SafeRef(rid, pUnk) = DLL("comsvcs.dll", "void* SafeRef(void*, void*)")
# 呼び出し: SafeRef(rid, pUnk)
# rid : GUID* -> "void*"
# pUnk : IUnknown* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。