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

SafeArrayCopy

関数
セーフ配列をデータ込みで複製し、新しいセーフ配列を作成する。
DLLOLEAUT32.dll呼出規約winapi

シグネチャ

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

HRESULT SafeArrayCopy(
    SAFEARRAY* psa,
    SAFEARRAY** ppsaOut
);

パラメーター

名前方向
psaSAFEARRAY*in
ppsaOutSAFEARRAY**out

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

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

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

var (
	oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
	procSafeArrayCopy = oleaut32.NewProc("SafeArrayCopy")
)

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