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

SafeArrayAddRef

関数
SAFEARRAYの参照カウントを増やしロックする。
DLLOLEAUT32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT SafeArrayAddRef(
    SAFEARRAY* psa,
    void** ppDataToRelease
);

パラメーター

名前方向
psaSAFEARRAY*in
ppDataToReleasevoid**out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SafeArrayAddRef(
    SAFEARRAY* psa,
    void** ppDataToRelease
);
[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern int SafeArrayAddRef(
    IntPtr psa,   // SAFEARRAY*
    IntPtr ppDataToRelease   // void** out
);
<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Function SafeArrayAddRef(
    psa As IntPtr,   ' SAFEARRAY*
    ppDataToRelease As IntPtr   ' void** out
) As Integer
End Function
' psa : SAFEARRAY*
' ppDataToRelease : void** out
Declare PtrSafe Function SafeArrayAddRef Lib "oleaut32" ( _
    ByVal psa As LongPtr, _
    ByVal ppDataToRelease As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SafeArrayAddRef = ctypes.windll.oleaut32.SafeArrayAddRef
SafeArrayAddRef.restype = ctypes.c_int
SafeArrayAddRef.argtypes = [
    ctypes.c_void_p,  # psa : SAFEARRAY*
    ctypes.c_void_p,  # ppDataToRelease : void** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
	procSafeArrayAddRef = oleaut32.NewProc("SafeArrayAddRef")
)

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