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

JsParseScript

関数
JavaScriptスクリプトを解析し、実行可能な関数オブジェクトを生成する。
DLLchakra.dll呼出規約winapi

シグネチャ

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

JsErrorCode JsParseScript(
    LPCWSTR script,
    UINT_PTR sourceContext,
    LPCWSTR sourceUrl,
    void** result
);

パラメーター

名前方向
scriptLPCWSTRin
sourceContextUINT_PTRin
sourceUrlLPCWSTRin
resultvoid**out

戻り値の型: JsErrorCode

各言語での呼び出し定義

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

JsErrorCode JsParseScript(
    LPCWSTR script,
    UINT_PTR sourceContext,
    LPCWSTR sourceUrl,
    void** result
);
[DllImport("chakra.dll", ExactSpelling = true)]
static extern uint JsParseScript(
    [MarshalAs(UnmanagedType.LPWStr)] string script,   // LPCWSTR
    UIntPtr sourceContext,   // UINT_PTR
    [MarshalAs(UnmanagedType.LPWStr)] string sourceUrl,   // LPCWSTR
    IntPtr result   // void** out
);
<DllImport("chakra.dll", ExactSpelling:=True)>
Public Shared Function JsParseScript(
    <MarshalAs(UnmanagedType.LPWStr)> script As String,   ' LPCWSTR
    sourceContext As UIntPtr,   ' UINT_PTR
    <MarshalAs(UnmanagedType.LPWStr)> sourceUrl As String,   ' LPCWSTR
    result As IntPtr   ' void** out
) As UInteger
End Function
' script : LPCWSTR
' sourceContext : UINT_PTR
' sourceUrl : LPCWSTR
' result : void** out
Declare PtrSafe Function JsParseScript Lib "chakra" ( _
    ByVal script As LongPtr, _
    ByVal sourceContext As LongPtr, _
    ByVal sourceUrl As LongPtr, _
    ByVal result As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

JsParseScript = ctypes.windll.chakra.JsParseScript
JsParseScript.restype = wintypes.DWORD
JsParseScript.argtypes = [
    wintypes.LPCWSTR,  # script : LPCWSTR
    ctypes.c_size_t,  # sourceContext : UINT_PTR
    wintypes.LPCWSTR,  # sourceUrl : LPCWSTR
    ctypes.c_void_p,  # result : void** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('chakra.dll')
JsParseScript = Fiddle::Function.new(
  lib['JsParseScript'],
  [
    Fiddle::TYPE_VOIDP,  # script : LPCWSTR
    Fiddle::TYPE_UINTPTR_T,  # sourceContext : UINT_PTR
    Fiddle::TYPE_VOIDP,  # sourceUrl : LPCWSTR
    Fiddle::TYPE_VOIDP,  # result : void** out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "chakra")]
extern "system" {
    fn JsParseScript(
        script: *const u16,  // LPCWSTR
        sourceContext: usize,  // UINT_PTR
        sourceUrl: *const u16,  // LPCWSTR
        result: *mut *mut ()  // void** out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("chakra.dll")]
public static extern uint JsParseScript([MarshalAs(UnmanagedType.LPWStr)] string script, UIntPtr sourceContext, [MarshalAs(UnmanagedType.LPWStr)] string sourceUrl, IntPtr result);
"@
$api = Add-Type -MemberDefinition $sig -Name 'chakra_JsParseScript' -Namespace Win32 -PassThru
# $api::JsParseScript(script, sourceContext, sourceUrl, result)
#uselib "chakra.dll"
#func global JsParseScript "JsParseScript" sptr, sptr, sptr, sptr
; JsParseScript script, sourceContext, sourceUrl, result   ; 戻り値は stat
; script : LPCWSTR -> "sptr"
; sourceContext : UINT_PTR -> "sptr"
; sourceUrl : LPCWSTR -> "sptr"
; result : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "chakra.dll"
#cfunc global JsParseScript "JsParseScript" wstr, sptr, wstr, sptr
; res = JsParseScript(script, sourceContext, sourceUrl, result)
; script : LPCWSTR -> "wstr"
; sourceContext : UINT_PTR -> "sptr"
; sourceUrl : LPCWSTR -> "wstr"
; result : void** out -> "sptr"
; JsErrorCode JsParseScript(LPCWSTR script, UINT_PTR sourceContext, LPCWSTR sourceUrl, void** result)
#uselib "chakra.dll"
#cfunc global JsParseScript "JsParseScript" wstr, intptr, wstr, intptr
; res = JsParseScript(script, sourceContext, sourceUrl, result)
; script : LPCWSTR -> "wstr"
; sourceContext : UINT_PTR -> "intptr"
; sourceUrl : LPCWSTR -> "wstr"
; result : void** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	chakra = windows.NewLazySystemDLL("chakra.dll")
	procJsParseScript = chakra.NewProc("JsParseScript")
)

// script (LPCWSTR), sourceContext (UINT_PTR), sourceUrl (LPCWSTR), result (void** out)
r1, _, err := procJsParseScript.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(script))),
	uintptr(sourceContext),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(sourceUrl))),
	uintptr(result),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // JsErrorCode
function JsParseScript(
  script: PWideChar;   // LPCWSTR
  sourceContext: NativeUInt;   // UINT_PTR
  sourceUrl: PWideChar;   // LPCWSTR
  result: Pointer   // void** out
): DWORD; stdcall;
  external 'chakra.dll' name 'JsParseScript';
result := DllCall("chakra\JsParseScript"
    , "WStr", script   ; LPCWSTR
    , "UPtr", sourceContext   ; UINT_PTR
    , "WStr", sourceUrl   ; LPCWSTR
    , "Ptr", result   ; void** out
    , "UInt")   ; return: JsErrorCode
●JsParseScript(script, sourceContext, sourceUrl, result) = DLL("chakra.dll", "dword JsParseScript(char*, int, char*, void*)")
# 呼び出し: JsParseScript(script, sourceContext, sourceUrl, result)
# script : LPCWSTR -> "char*"
# sourceContext : UINT_PTR -> "int"
# sourceUrl : LPCWSTR -> "char*"
# result : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。