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

SafeArrayGetUBound

関数
SAFEARRAYの指定次元の上限インデックスを取得する。
DLLOLEAUT32.dll呼出規約winapi

シグネチャ

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

HRESULT SafeArrayGetUBound(
    SAFEARRAY* psa,
    DWORD nDim,
    INT* plUbound
);

パラメーター

名前方向
psaSAFEARRAY*in
nDimDWORDin
plUboundINT*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

SafeArrayGetUBound = ctypes.windll.oleaut32.SafeArrayGetUBound
SafeArrayGetUBound.restype = ctypes.c_int
SafeArrayGetUBound.argtypes = [
    ctypes.c_void_p,  # psa : SAFEARRAY*
    wintypes.DWORD,  # nDim : DWORD
    ctypes.POINTER(ctypes.c_int),  # plUbound : INT* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
	procSafeArrayGetUBound = oleaut32.NewProc("SafeArrayGetUBound")
)

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