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

JsCallFunction

関数
JavaScript関数を引数を渡して呼び出す。
DLLchakra.dll呼出規約winapi

シグネチャ

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

JsErrorCode JsCallFunction(
    void* function,
    void** arguments,
    WORD argumentCount,
    void** result   // optional
);

パラメーター

名前方向
functionvoid*in
argumentsvoid**in
argumentCountWORDin
resultvoid**outoptional

戻り値の型: JsErrorCode

各言語での呼び出し定義

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

JsErrorCode JsCallFunction(
    void* function,
    void** arguments,
    WORD argumentCount,
    void** result   // optional
);
[DllImport("chakra.dll", ExactSpelling = true)]
static extern uint JsCallFunction(
    IntPtr function,   // void*
    IntPtr arguments,   // void**
    ushort argumentCount,   // WORD
    IntPtr result   // void** optional, out
);
<DllImport("chakra.dll", ExactSpelling:=True)>
Public Shared Function JsCallFunction(
    [function] As IntPtr,   ' void*
    arguments As IntPtr,   ' void**
    argumentCount As UShort,   ' WORD
    result As IntPtr   ' void** optional, out
) As UInteger
End Function
' function : void*
' arguments : void**
' argumentCount : WORD
' result : void** optional, out
Declare PtrSafe Function JsCallFunction Lib "chakra" ( _
    ByVal function As LongPtr, _
    ByVal arguments As LongPtr, _
    ByVal argumentCount As Integer, _
    ByVal result As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

JsCallFunction = ctypes.windll.chakra.JsCallFunction
JsCallFunction.restype = wintypes.DWORD
JsCallFunction.argtypes = [
    ctypes.POINTER(None),  # function : void*
    ctypes.c_void_p,  # arguments : void**
    ctypes.c_ushort,  # argumentCount : WORD
    ctypes.c_void_p,  # result : void** optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('chakra.dll')
JsCallFunction = Fiddle::Function.new(
  lib['JsCallFunction'],
  [
    Fiddle::TYPE_VOIDP,  # function : void*
    Fiddle::TYPE_VOIDP,  # arguments : void**
    -Fiddle::TYPE_SHORT,  # argumentCount : WORD
    Fiddle::TYPE_VOIDP,  # result : void** optional, out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "chakra")]
extern "system" {
    fn JsCallFunction(
        function: *mut (),  // void*
        arguments: *mut *mut (),  // void**
        argumentCount: u16,  // WORD
        result: *mut *mut ()  // void** optional, out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("chakra.dll")]
public static extern uint JsCallFunction(IntPtr function, IntPtr arguments, ushort argumentCount, IntPtr result);
"@
$api = Add-Type -MemberDefinition $sig -Name 'chakra_JsCallFunction' -Namespace Win32 -PassThru
# $api::JsCallFunction(function, arguments, argumentCount, result)
#uselib "chakra.dll"
#func global JsCallFunction "JsCallFunction" sptr, sptr, sptr, sptr
; JsCallFunction function, arguments, argumentCount, result   ; 戻り値は stat
; function : void* -> "sptr"
; arguments : void** -> "sptr"
; argumentCount : WORD -> "sptr"
; result : void** optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "chakra.dll"
#cfunc global JsCallFunction "JsCallFunction" sptr, sptr, int, sptr
; res = JsCallFunction(function, arguments, argumentCount, result)
; function : void* -> "sptr"
; arguments : void** -> "sptr"
; argumentCount : WORD -> "int"
; result : void** optional, out -> "sptr"
; JsErrorCode JsCallFunction(void* function, void** arguments, WORD argumentCount, void** result)
#uselib "chakra.dll"
#cfunc global JsCallFunction "JsCallFunction" intptr, intptr, int, intptr
; res = JsCallFunction(function, arguments, argumentCount, result)
; function : void* -> "intptr"
; arguments : void** -> "intptr"
; argumentCount : WORD -> "int"
; result : void** optional, out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	chakra = windows.NewLazySystemDLL("chakra.dll")
	procJsCallFunction = chakra.NewProc("JsCallFunction")
)

// function (void*), arguments (void**), argumentCount (WORD), result (void** optional, out)
r1, _, err := procJsCallFunction.Call(
	uintptr(function),
	uintptr(arguments),
	uintptr(argumentCount),
	uintptr(result),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // JsErrorCode
function JsCallFunction(
  function: Pointer;   // void*
  arguments: Pointer;   // void**
  argumentCount: Word;   // WORD
  result: Pointer   // void** optional, out
): DWORD; stdcall;
  external 'chakra.dll' name 'JsCallFunction';
result := DllCall("chakra\JsCallFunction"
    , "Ptr", function   ; void*
    , "Ptr", arguments   ; void**
    , "UShort", argumentCount   ; WORD
    , "Ptr", result   ; void** optional, out
    , "UInt")   ; return: JsErrorCode
●JsCallFunction(function, arguments, argumentCount, result) = DLL("chakra.dll", "dword JsCallFunction(void*, void*, int, void*)")
# 呼び出し: JsCallFunction(function, arguments, argumentCount, result)
# function : void* -> "void*"
# arguments : void** -> "void*"
# argumentCount : WORD -> "int"
# result : void** optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。