ホーム › System.Ole › DispCallFunc
DispCallFunc
関数仮想関数テーブルの指定メソッドを動的に呼び出す。
シグネチャ
// OLEAUT32.dll
#include <windows.h>
HRESULT DispCallFunc(
void* pvInstance, // optional
UINT_PTR oVft,
CALLCONV cc,
VARENUM vtReturn,
DWORD cActuals,
WORD* prgvt,
VARIANT** prgpvarg,
VARIANT* pvargResult
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pvInstance | void* | inoptional |
| oVft | UINT_PTR | in |
| cc | CALLCONV | in |
| vtReturn | VARENUM | in |
| cActuals | DWORD | in |
| prgvt | WORD* | in |
| prgpvarg | VARIANT** | in |
| pvargResult | VARIANT* | out |
戻り値の型: HRESULT
各言語での呼び出し定義
// OLEAUT32.dll
#include <windows.h>
HRESULT DispCallFunc(
void* pvInstance, // optional
UINT_PTR oVft,
CALLCONV cc,
VARENUM vtReturn,
DWORD cActuals,
WORD* prgvt,
VARIANT** prgpvarg,
VARIANT* pvargResult
);[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern int DispCallFunc(
IntPtr pvInstance, // void* optional
UIntPtr oVft, // UINT_PTR
int cc, // CALLCONV
ushort vtReturn, // VARENUM
uint cActuals, // DWORD
ref ushort prgvt, // WORD*
IntPtr prgpvarg, // VARIANT**
IntPtr pvargResult // VARIANT* out
);<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Function DispCallFunc(
pvInstance As IntPtr, ' void* optional
oVft As UIntPtr, ' UINT_PTR
cc As Integer, ' CALLCONV
vtReturn As UShort, ' VARENUM
cActuals As UInteger, ' DWORD
ByRef prgvt As UShort, ' WORD*
prgpvarg As IntPtr, ' VARIANT**
pvargResult As IntPtr ' VARIANT* out
) As Integer
End Function' pvInstance : void* optional
' oVft : UINT_PTR
' cc : CALLCONV
' vtReturn : VARENUM
' cActuals : DWORD
' prgvt : WORD*
' prgpvarg : VARIANT**
' pvargResult : VARIANT* out
Declare PtrSafe Function DispCallFunc Lib "oleaut32" ( _
ByVal pvInstance As LongPtr, _
ByVal oVft As LongPtr, _
ByVal cc As Long, _
ByVal vtReturn As Integer, _
ByVal cActuals As Long, _
ByRef prgvt As Integer, _
ByVal prgpvarg As LongPtr, _
ByVal pvargResult As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DispCallFunc = ctypes.windll.oleaut32.DispCallFunc
DispCallFunc.restype = ctypes.c_int
DispCallFunc.argtypes = [
ctypes.POINTER(None), # pvInstance : void* optional
ctypes.c_size_t, # oVft : UINT_PTR
ctypes.c_int, # cc : CALLCONV
ctypes.c_ushort, # vtReturn : VARENUM
wintypes.DWORD, # cActuals : DWORD
ctypes.POINTER(ctypes.c_ushort), # prgvt : WORD*
ctypes.c_void_p, # prgpvarg : VARIANT**
ctypes.c_void_p, # pvargResult : VARIANT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLEAUT32.dll')
DispCallFunc = Fiddle::Function.new(
lib['DispCallFunc'],
[
Fiddle::TYPE_VOIDP, # pvInstance : void* optional
Fiddle::TYPE_UINTPTR_T, # oVft : UINT_PTR
Fiddle::TYPE_INT, # cc : CALLCONV
-Fiddle::TYPE_SHORT, # vtReturn : VARENUM
-Fiddle::TYPE_INT, # cActuals : DWORD
Fiddle::TYPE_VOIDP, # prgvt : WORD*
Fiddle::TYPE_VOIDP, # prgpvarg : VARIANT**
Fiddle::TYPE_VOIDP, # pvargResult : VARIANT* out
],
Fiddle::TYPE_INT)#[link(name = "oleaut32")]
extern "system" {
fn DispCallFunc(
pvInstance: *mut (), // void* optional
oVft: usize, // UINT_PTR
cc: i32, // CALLCONV
vtReturn: u16, // VARENUM
cActuals: u32, // DWORD
prgvt: *mut u16, // WORD*
prgpvarg: *mut *mut VARIANT, // VARIANT**
pvargResult: *mut VARIANT // VARIANT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLEAUT32.dll")]
public static extern int DispCallFunc(IntPtr pvInstance, UIntPtr oVft, int cc, ushort vtReturn, uint cActuals, ref ushort prgvt, IntPtr prgpvarg, IntPtr pvargResult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLEAUT32_DispCallFunc' -Namespace Win32 -PassThru
# $api::DispCallFunc(pvInstance, oVft, cc, vtReturn, cActuals, prgvt, prgpvarg, pvargResult)#uselib "OLEAUT32.dll"
#func global DispCallFunc "DispCallFunc" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DispCallFunc pvInstance, oVft, cc, vtReturn, cActuals, varptr(prgvt), varptr(prgpvarg), varptr(pvargResult) ; 戻り値は stat
; pvInstance : void* optional -> "sptr"
; oVft : UINT_PTR -> "sptr"
; cc : CALLCONV -> "sptr"
; vtReturn : VARENUM -> "sptr"
; cActuals : DWORD -> "sptr"
; prgvt : WORD* -> "sptr"
; prgpvarg : VARIANT** -> "sptr"
; pvargResult : VARIANT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "OLEAUT32.dll" #cfunc global DispCallFunc "DispCallFunc" sptr, sptr, int, int, int, var, var, var ; res = DispCallFunc(pvInstance, oVft, cc, vtReturn, cActuals, prgvt, prgpvarg, pvargResult) ; pvInstance : void* optional -> "sptr" ; oVft : UINT_PTR -> "sptr" ; cc : CALLCONV -> "int" ; vtReturn : VARENUM -> "int" ; cActuals : DWORD -> "int" ; prgvt : WORD* -> "var" ; prgpvarg : VARIANT** -> "var" ; pvargResult : VARIANT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "OLEAUT32.dll" #cfunc global DispCallFunc "DispCallFunc" sptr, sptr, int, int, int, sptr, sptr, sptr ; res = DispCallFunc(pvInstance, oVft, cc, vtReturn, cActuals, varptr(prgvt), varptr(prgpvarg), varptr(pvargResult)) ; pvInstance : void* optional -> "sptr" ; oVft : UINT_PTR -> "sptr" ; cc : CALLCONV -> "int" ; vtReturn : VARENUM -> "int" ; cActuals : DWORD -> "int" ; prgvt : WORD* -> "sptr" ; prgpvarg : VARIANT** -> "sptr" ; pvargResult : VARIANT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT DispCallFunc(void* pvInstance, UINT_PTR oVft, CALLCONV cc, VARENUM vtReturn, DWORD cActuals, WORD* prgvt, VARIANT** prgpvarg, VARIANT* pvargResult) #uselib "OLEAUT32.dll" #cfunc global DispCallFunc "DispCallFunc" intptr, intptr, int, int, int, var, var, var ; res = DispCallFunc(pvInstance, oVft, cc, vtReturn, cActuals, prgvt, prgpvarg, pvargResult) ; pvInstance : void* optional -> "intptr" ; oVft : UINT_PTR -> "intptr" ; cc : CALLCONV -> "int" ; vtReturn : VARENUM -> "int" ; cActuals : DWORD -> "int" ; prgvt : WORD* -> "var" ; prgpvarg : VARIANT** -> "var" ; pvargResult : VARIANT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT DispCallFunc(void* pvInstance, UINT_PTR oVft, CALLCONV cc, VARENUM vtReturn, DWORD cActuals, WORD* prgvt, VARIANT** prgpvarg, VARIANT* pvargResult) #uselib "OLEAUT32.dll" #cfunc global DispCallFunc "DispCallFunc" intptr, intptr, int, int, int, intptr, intptr, intptr ; res = DispCallFunc(pvInstance, oVft, cc, vtReturn, cActuals, varptr(prgvt), varptr(prgpvarg), varptr(pvargResult)) ; pvInstance : void* optional -> "intptr" ; oVft : UINT_PTR -> "intptr" ; cc : CALLCONV -> "int" ; vtReturn : VARENUM -> "int" ; cActuals : DWORD -> "int" ; prgvt : WORD* -> "intptr" ; prgpvarg : VARIANT** -> "intptr" ; pvargResult : VARIANT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
procDispCallFunc = oleaut32.NewProc("DispCallFunc")
)
// pvInstance (void* optional), oVft (UINT_PTR), cc (CALLCONV), vtReturn (VARENUM), cActuals (DWORD), prgvt (WORD*), prgpvarg (VARIANT**), pvargResult (VARIANT* out)
r1, _, err := procDispCallFunc.Call(
uintptr(pvInstance),
uintptr(oVft),
uintptr(cc),
uintptr(vtReturn),
uintptr(cActuals),
uintptr(prgvt),
uintptr(prgpvarg),
uintptr(pvargResult),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction DispCallFunc(
pvInstance: Pointer; // void* optional
oVft: NativeUInt; // UINT_PTR
cc: Integer; // CALLCONV
vtReturn: Word; // VARENUM
cActuals: DWORD; // DWORD
prgvt: Pointer; // WORD*
prgpvarg: Pointer; // VARIANT**
pvargResult: Pointer // VARIANT* out
): Integer; stdcall;
external 'OLEAUT32.dll' name 'DispCallFunc';result := DllCall("OLEAUT32\DispCallFunc"
, "Ptr", pvInstance ; void* optional
, "UPtr", oVft ; UINT_PTR
, "Int", cc ; CALLCONV
, "UShort", vtReturn ; VARENUM
, "UInt", cActuals ; DWORD
, "Ptr", prgvt ; WORD*
, "Ptr", prgpvarg ; VARIANT**
, "Ptr", pvargResult ; VARIANT* out
, "Int") ; return: HRESULT●DispCallFunc(pvInstance, oVft, cc, vtReturn, cActuals, prgvt, prgpvarg, pvargResult) = DLL("OLEAUT32.dll", "int DispCallFunc(void*, int, int, int, dword, void*, void*, void*)")
# 呼び出し: DispCallFunc(pvInstance, oVft, cc, vtReturn, cActuals, prgvt, prgpvarg, pvargResult)
# pvInstance : void* optional -> "void*"
# oVft : UINT_PTR -> "int"
# cc : CALLCONV -> "int"
# vtReturn : VARENUM -> "int"
# cActuals : DWORD -> "dword"
# prgvt : WORD* -> "void*"
# prgpvarg : VARIANT** -> "void*"
# pvargResult : VARIANT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。