Jump to content
Sign in to follow this  
junkew

Chakra native Javascript runtime JSRT

Recommended Posts

Since W8.1 (actually IE 11 with W7 will work also) microsoft has a Javascript runtime that can be called from scripting languages

As shown in this example from C++: https://iobservable.net/blog/2013/11/12/introduction-to-jsrt/

By loading either JSCRIPT9.DLL or CHAKRA.DLL you can embed ECMA JavaScript in your application

And implemented here in AutoHotKey https://autohotkey.com/boards/viewtopic.php?f=6&t=5739

Triggered by other threads: 

This code is almost working but unfortunately not with the expected output. Someone seeing what is wrong? 
It runs completely after fixes of DanyFirex 

 

;~ https://iobservable.net/blog/2013/11/
;~ Should work on all windows versions with IE11

#AutoIt3Wrapper_UseX64=N
#Region enum JsErrorCode : unsigned int
Enum $JsNoError = 0, _
        $JsErrorCategoryUsage = 0x10000, _
        $JsErrorInvalidArgument, _
        $JsErrorNullArgument, _
        $JsErrorNoCurrentContext, _
        $JsErrorInExceptionState, _
        $JsErrorNotImplemented, _
        $JsErrorWrongThread, _
        $JsErrorRuntimeInUse, _
        $JsErrorBadSerializedScript, _
        $JsErrorInDisabledState, _
        $JsErrorCannotDisableExecution, _
        $JsErrorHeapEnumInProgress, _
        $JsErrorArgumentNotObject, _
        $JsErrorInProfileCallback, _
        $JsErrorInThreadServiceCallback, _
        $JsErrorCannotSerializeDebugScript, _
        $JsErrorAlreadyDebuggingContext, _
        $JsErrorAlreadyProfilingContext, _
        $JsErrorIdleNotEnabled, _
        $JsErrorCategoryEngine = 0x20000, _
        $JsErrorOutOfMemory, _
        $JsErrorCategoryScript = 0x30000, _
        $JsErrorScriptException, _
        $JsErrorScriptCompile, _
        $JsErrorScriptTerminated, _
        $JsErrorScriptEvalDisabled, _
        $JsErrorCategoryFatal = 0x40000, _
        $JsErrorFatal
;~    }JsErrorCode;
#EndRegion enum JsErrorCode : unsigned int
#Region    typedef enum JsRuntimeVersion
Enum $JsRuntimeVersion10 = 0, $JsRuntimeVersion11 = 1
#EndRegion typedef enum JsRuntimeVersion

; Create callback function.
Local $hPrintf = DllCallbackRegister("_printf", "long", "ptr;bool;ptr;ushort;ptr")
Local $hJSRuntime = DllOpen("c:\windows\system32\jscript9.dll")
$JsRuntimeAttributeNone = 0x00000000

;~ #RequireAdmin
Example()

Func Example()

    Local $script = "native.printf('hello world')"
;~  Local $script = "native.printf('number=%#x string=%s\n', 255, 'test')"

;~  Local $script = "(()=>{return 'Hello world!';})()"
;~  Local $script = "var x='helloworld'; return x;"
;~  Local $script = "var x=10;" & @CRLF & "var y=11;"
;~  Local $script = "(42);"
;~ Local $script = "(" & @CRLF
;~ $script=$script & "host.echo(JSON.stringify({foo:'bar'}));)" & @CRLF
;~ $script=$script & "42 // The script's result :) "& @CRLF
;~ $script=$script & ")"& @CRLF
;~ $script=$script & "class Host {"& @CRLF
;~ $script=$script & "    echo(s) {"& @CRLF
;~ $script=$script & "        MsgBox %s%"& @CRLF
;~ $script=$script & "    }"& @CRLF
;~ $script=$script & "}"& @CRLF

    Local $aResult
    Local $runtime
    Local $context

;~  // Create a runtime
;~      JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &runtime);
    $runtime = _JsCreateRuntime($JsRuntimeAttributeNone, 0, $runtime) ;

;~  // Create an execution context.
;~      JsCreateContext(runtime, &context);
    $context = _JsCreateContext($runtime, $context)

;~     // Now set the current execution context.
;~     JsSetCurrentContext(context);
    _JsSetCurrentContext($context) ;

    ; Get the Global object for adding stuff
;~ JsGetGlobalObject(&global);
    Local $global
    $global = _JsGetGlobalObject($global)

;~ JsPropertyIdRef nativeProp;
;~ JsGetPropertyIdFromName(L"native", &nativeProp);
    Local $nativeProp
    $nativeProp = _JsGetPropertyIdFromName("native", $nativeProp)

;~ JsValueRef nativeObj;
;~ JsCreateObject(&nativeObj);
    Local $nativeObj
    $nativeObj = _JsCreateObject($nativeObj)

;~ JsPropertyIdRef printfProp;
;~ JsGetPropertyIdFromName(L"printf", &printfProp);
    Local $printfProp
    $printfProp = _JsGetPropertyIdFromName("printf", $printfProp)

;~ JsValueRef printfFunc;
;~ JsCreateFunction(PrintFormat, nullptr, &printfFunc);
    Local $printfFunc
    $printfFunc = _JsCreateFunction(DllCallbackGetPtr($hPrintf), 0, $printfFunc)

;~ JsSetProperty(nativeObj, printfProp, printfFunc, true);
    _JsSetProperty($nativeObj, $printfProp, $printfFunc, True)

;~ JsSetProperty(global, nativeProp, nativeObj, true);
    _JsSetProperty($global, $nativeProp, $nativeObj, True)

;~ STDAPI_(JsErrorCode) JsCreateFunction(
;~    _In_ JsNativeFunction nativeFunction,
;~    _In_opt_ void *callbackState,
;~    _Out_ JsValueRef *function
;~ );

    ; Get a JsValueRef for our Host object
;~ hostRef := ToJsValue(Host)
;~ $aResult=DllCall($hJSRuntime, "int","JsVariantToValue", "ptr", &variant, "ptr*", valref)
    ; Pass our Host object to the script engine
;~ DllCall("jscript9\JsSetProperty", "ptr", globalObject, "ptr", hostPropertyId, "ptr", hostRef, "int", true)

;~     // Run the script.
;~ STDAPI_(JsErrorCode) JsRunScript(
;~    _In_z_ const wchar_t *script,
;~    _In_ JsSourceContext sourceContext,
;~    _In_z_ const wchar_t *sourceUrl,
;~    _Out_ JsValueRef *result
;~ );
    Local $currentSourceContext = 1

;~     JsRunScript(script.c_str(), currentSourceContext++, L"", &result);
    Local $result = ""
    Local $sourceURL = ""
    $aResult = DllCall($hJSRuntime, "int", "JsRunScript", "WSTR", $script, "UINT*", $currentSourceContext, "wstr", "dummysource.js", "WSTR*", $result)
    ConsoleWrite("Error 11: " & @error & @CRLF)
    If @error = 0 Then
        ConsoleWrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] & ";" & $aResult[3] & ";" & $aResult[4] & @CRLF)

    EndIf

;~ // Convert your script result to String in JavaScript redundant if your script returns a String
;~     JsValueRef resultJSString;
;~ STDAPI_(JsErrorCode) JsConvertValueToString(
;~    _In_ JsValueRef value,
;~    _Out_ JsValueRef *stringValue
;~ );
;~     JsConvertValueToString(result, &resultJSString);
;~  $aResult=DllCall($hJSRuntime, "int", "JsConvertValueToString", "WSTR", $script, "long", 1, "WSTR*",0, "WSTR*", $result)
;~  consolewrite("Error 4: " & @error & @CRLF)
;~  if @error=0 Then
;~      consolewrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] &  ";" & $aResult[3] &  ";" & $aResult[4] & @CRLF)
;~  EndIf
;~
;~     // Project script result back to C++.
;~     const wchar_t *resultWC;
;~     size_t stringLength;
;~     JsStringToPointer(resultJSString, &resultWC, &stringLength);

;~     wstring resultW(resultWC);
;~     cout << string(resultW.begin(), resultW.end()) << endl;
;~     system("pause");

;~     // Dispose runtime
;~     JsSetCurrentContext(JS_INVALID_REFERENCE);
;~     JsDisposeRuntime(runtime);

    Return 0 ;


EndFunc   ;==>Example



; Create callback function.
;~ JsValueRef CALLBACK PrintFormat(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
;~ {
;~  const wchar_t *format;
;~  size_t length;
;~  JsStringToPointer(arguments[1], &format, &length);

;~  VARIANT variant;
;~  JsValueToVariant(arguments[2], &variant);

;~  const wchar_t *str;
;~  JsStringToPointer(arguments[3], &str, &length);

;~  wprintf(format, variant.intVal, str);

;~  return JS_INVALID_REFERENCE;
;~ }
;~ typedef _Ret_maybenull_ JsValueRef (CALLBACK * JsNativeFunction)(
;~    _In_ JsValueRef callee,
;~    _In_ bool isConstructCall,
;~    _In_ JsValueRef *arguments,
;~    _In_ unsigned short argumentCount
;~ );

Func _printf($callee, $isConstructCall, $arguments, $argumentCount, $callbackState)
    ConsoleWrite("there we are with " & $argumentCount & " arguments" & @CRLF)


    Local $tArgs = DllStructCreate("ptr JsValues[" & $argumentCount & "]", $arguments)
;~  STDAPI_(JsErrorCode) JsConvertValueToString(
;~    _In_ JsValueRef value,
;~    _Out_ JsValueRef *stringValue
;~ );
;~     JsConvertValueToString(result, &resultJSString);
    local $tresult
    $aResult=DllCall($hJSRuntime, "int", "JsConvertValueToString", "ptr", DllStructGetData($tArgs,1,2), "ptr*", $tresult)
    consolewrite("Error 4: " & @error & @CRLF)
    if @error=0 Then
        consolewrite( $aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] & @CRLF)
        $tresult=$aresult[2]
    EndIf

;~ STDAPI_(JsErrorCode) JsValueToVariant(
;~    _In_ JsValueRef object,
;~    _Out_ VARIANT *variant
;~ );
;~     Local $aResult = DllCall($hJSRuntime, "dword", "JsValueToVariant", "ptr", $arguments[0], "ptr*", 0)
;~     If @error Then Return SetError(3, 0, @error)
;~     If $aResult[0] <> 0 Then Return SetError(4, 0, $aResult[0])
;~     consolewrite($aResult[2])

 Local $aResult = DllCall($hJSRuntime, "dword", "JsStringToPointer", "ptr", $tResult, "ptr*", 0, "int*", 0)
 If @error Then Return SetError(3, 0, @error)
 If $aResult[0] <> 0 Then Return SetError(4, 0, $aResult[0])

 Local $tString = DllStructCreate("wchar string["&$aResult[3]&"]", $aResult[2])
 consolewrite("+Parameter: " & $tString.string & @CRLF)




    Return 0
EndFunc   ;==>_printf


;~ typedef void *JsRuntimeHandle;
;~  // Create a runtime.
;~  Edge mode signature STDAPI_(JsErrorCode) JsCreateRuntime(
;~    _In_ JsRuntimeAttributes attributes,
;~    _In_opt_ JsThreadServiceCallback threadService,
;~    _Out_ JsRuntimeHandle *runtime);
;~ Legacy mode signature
;~ STDAPI_(JsErrorCode) JsCreateRuntime(
;~    _In_ JsRuntimeAttributes attributes,
;~    _In_ JsRuntimeVersion version,
;~    _In_opt_ JsThreadServiceCallback threadService,
;~    _Out_ JsRuntimeHandle *runtime
;~ );
;~  $runtime=_JsCreateRuntime(JsRuntimeAttributeNone, 0, $runtime);
Func _JsCreateRuntime($JsRuntimeAttributeNone, $JSRuntimeVersion, $runtime)
    $aResult = DllCall($hJSRuntime, "int", "JsCreateRuntime", "int", $JsRuntimeAttributeNone, "int", $JSRuntimeVersion, "ptr", 0, "ptr*", $runtime)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[4]
EndFunc   ;==>_JsCreateRuntime

;~ // Edge mode signature
;~ STDAPI_(JsErrorCode) JsCreateContext(
;~    _In_ JsRuntimeHandle runtime,
;~    _Out_ JsContextRef *newContext);

;~ // Legacy mode signature
;~ STDAPI_(JsErrorCode) JsCreateContext(
;~    _In_ JsRuntimeHandle runtime,
;~    _In_ IDebugApplication *debugApplication,
;~    _Out_ JsContextRef *newContext
;~ );
;~      JsCreateContext(runtime, &context);
Func _JsCreateContext($runtime, $context)
    $aResult = DllCall($hJSRuntime, "int", "JsCreateContext", "ptr", $runtime, "ptr", 0, "ptr*", $context)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[3]
EndFunc   ;==>_JsCreateContext

;~ STDAPI_(JsErrorCode) JsSetCurrentContext(
;~    _In_ JsContextRef context
;~ );
;~     JsSetCurrentContext(context);
Func _JsSetCurrentContext($context)
    $aResult = DllCall($hJSRuntime, "int", "JsSetCurrentContext", "ptr", $context)
    If @error Then Return SetError(1, @error, 0)
    Return $JsNoError
EndFunc   ;==>_JsSetCurrentContext

; Get the Global object for adding stuff
;~ STDAPI_(JsErrorCode) JsGetGlobalObject(
;~    _Out_ JsValueRef *globalObject
;~ );
;~ JsValueRef global;
;~ JsGetGlobalObject(&global);
Func _JsGetGlobalObject($global)
    $aResult = DllCall($hJSRuntime, "int", "JsGetGlobalObject", "ptr*", $global)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[1]
EndFunc   ;==>_JsGetGlobalObject

; Get a property ID for the name "host"
;~ STDAPI_(JsErrorCode) JsGetPropertyIdFromName(
;~    _In_z_ const wchar_t *name,
;~    _Out_ JsPropertyIdRef *propertyId
;~ );
;~ DllCall("jscript9\JsGetPropertyIdFromName", "wstr", "host", "ptr*", hostPropertyId)
;~ local $hostPropertyID
;~ $aResult=DllCall($hJSRuntime, "int","JsGetPropertyIdFromName", "wstr", "host", "ptr*", $hostPropertyId)
;~  consolewrite("Error 5: " & @error & @CRLF)
;~  if @error=0 Then
;~      consolewrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2]  & @CRLF)
;~  EndIf


;~ JsPropertyIdRef nativeProp;
;~ JsGetPropertyIdFromName(L"native", &nativeProp);
Func _JsGetPropertyIdFromName($propname, $nativeProp)
    $aResult = DllCall($hJSRuntime, "int", "JsGetPropertyIdFromName", "wstr", $propname, "ptr*", $nativeProp)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[2]
EndFunc   ;==>_JsGetPropertyIdFromName

;~ STDAPI_(JsErrorCode) JsCreateObject(
;~    _Out_ JsValueRef *object
;~ );
;~ JsValueRef nativeObj;
;~ JsCreateObject(&nativeObj);
Local $nativeObj
Func _JsCreateObject($JSRTobject)
    $aResult = DllCall($hJSRuntime, "int", "JsCreateObject", "ptr*", $JSRTobject)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[1]
EndFunc   ;==>_JsCreateObject

;~ STDAPI_(JsErrorCode) JsCreateFunction(
;~    _In_ JsNativeFunction nativeFunction,
;~    _In_opt_ void *callbackState,
;~    _Out_ JsValueRef *function
;~ );
Func _JsCreateFunction($fncCallBackPtr, $callbackState, $fncVar)
    $aResult = DllCall($hJSRuntime, "int", "JsCreateFunction", "ptr", $fncCallBackPtr, "ptr*", $callbackState, "ptr*", $fncVar)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[3]
EndFunc   ;==>_JsCreateFunction

;~ JsSetProperty(nativeObj, printfProp, printfFunc, true);
;~ STDAPI_(JsErrorCode) JsSetProperty(
;~    _In_ JsValueRef object,
;~    _In_ JsPropertyIdRef propertyId,
;~    _In_ JsValueRef value,
;~    _In_ bool useStrictRules
;~ );
Func _JsSetProperty($Obj, $Prop, $Func, $val) ;
    $aResult = DllCall($hJSRuntime, "int", "JsSetProperty", "ptr", $Obj, "ptr", $Prop, "ptr", $Func, "int", $val)
    If @error Then Return SetError(1, @error, 0)
EndFunc   ;==>_JsSetProperty

 

Edited by junkew
code example fixed

Share this post


Link to post
Share on other sites

Hello. I have not time to write code right now. But callback should be written like this https://github.com/Microsoft/ChakraCore/wiki/JsNativeFunction

Then read the parameter from  JsValueRef *arguments.

 

Saludos 

Edited by Danyfirex

Share this post


Link to post
Share on other sites

ok small steps new version of the script

  • cleaned up by making functions of some of the dll calls
  • matching parameter functions a little unclear
    Local $hPrintf = DllCallbackRegister("_printf", "long", "ptr;bool;ptr;ushort;ptr")

    ;~ typedef _Ret_maybenull_ JsValueRef (CALLBACK * JsNativeFunction)(
    ;~    _In_ JsValueRef callee,
    ;~    _In_ bool isConstructCall,
    ;~    _In_ JsValueRef *arguments,
    ;~    _In_ unsigned short argumentCount
    ;~ );

    func _printf($callee, $isConstructCall, $arguments, $argumentCount, $callbackState)

  • now unclear how to deal with the arguments array

;~ https://iobservable.net/blog/2013/11/
;~ Should work on all windows versions with IE11

#AutoIt3Wrapper_UseX64=N
#region enum JsErrorCode : unsigned int
enum $JsNoError = 0, _
    $JsErrorCategoryUsage = 0x10000, _
    $JsErrorInvalidArgument, _
    $JsErrorNullArgument, _
    $JsErrorNoCurrentContext, _
    $JsErrorInExceptionState, _
    $JsErrorNotImplemented, _
    $JsErrorWrongThread, _
    $JsErrorRuntimeInUse, _
    $JsErrorBadSerializedScript, _
    $JsErrorInDisabledState, _
    $JsErrorCannotDisableExecution, _
    $JsErrorHeapEnumInProgress, _
    $JsErrorArgumentNotObject, _
    $JsErrorInProfileCallback, _
    $JsErrorInThreadServiceCallback, _
    $JsErrorCannotSerializeDebugScript, _
    $JsErrorAlreadyDebuggingContext, _
    $JsErrorAlreadyProfilingContext, _
    $JsErrorIdleNotEnabled, _
    $JsErrorCategoryEngine = 0x20000, _
    $JsErrorOutOfMemory, _
    $JsErrorCategoryScript = 0x30000, _
    $JsErrorScriptException, _
    $JsErrorScriptCompile, _
    $JsErrorScriptTerminated, _
    $JsErrorScriptEvalDisabled, _
    $JsErrorCategoryFatal = 0x40000, _
    $JsErrorFatal
;~    }JsErrorCode;
#EndRegion
#region    typedef enum JsRuntimeVersion
enum $JsRuntimeVersion10 = 0, $JsRuntimeVersion11 = 1
#EndRegion

; Create callback function.
Local $hPrintf = DllCallbackRegister("_printf", "long", "ptr;bool;ptr;ushort;ptr")
Local $hJSRuntime = DllOpen("c:\windows\system32\jscript9.dll")
$JsRuntimeAttributeNone = 0x00000000

;~ #RequireAdmin
Example()

Func Example()

    Local $script = "native.printf('hello world')"
;~  Local $script = "native.printf('number=%#x string=%s\n', 255, 'test')"

;~  Local $script = "(()=>{return 'Hello world!';})()"
;~  Local $script = "var x='helloworld'; return x;"
;~  Local $script = "var x=10;" & @CRLF & "var y=11;"
;~  Local $script = "(42);"
;~ Local $script = "(" & @CRLF
;~ $script=$script & "host.echo(JSON.stringify({foo:'bar'}));)" & @CRLF
;~ $script=$script & "42 // The script's result :) "& @CRLF
;~ $script=$script & ")"& @CRLF
;~ $script=$script & "class Host {"& @CRLF
;~ $script=$script & "    echo(s) {"& @CRLF
;~ $script=$script & "        MsgBox %s%"& @CRLF
;~ $script=$script & "    }"& @CRLF
;~ $script=$script & "}"& @CRLF

    Local $aResult
    local $runtime
    local $context

;~  // Create a runtime
;~      JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &runtime);
    $runtime=_JsCreateRuntime($JsRuntimeAttributeNone, 0, $runtime);

;~  // Create an execution context.
;~      JsCreateContext(runtime, &context);
    $context=_JSCreateContext($runtime, $context)

;~     // Now set the current execution context.
;~     JsSetCurrentContext(context);
    _JsSetCurrentContext($context);

; Get the Global object for adding stuff
;~ JsGetGlobalObject(&global);
    local $global
    $global=_JsGetGlobalObject($global)

;~ JsPropertyIdRef nativeProp;
;~ JsGetPropertyIdFromName(L"native", &nativeProp);
    local $nativeProp
    $nativeprop=_JsGetPropertyIdFromName("native", $nativeprop)

;~ JsValueRef nativeObj;
;~ JsCreateObject(&nativeObj);
    local $nativeObj
    $nativeObj=_JsCreateObject($nativeObj)

;~ JsPropertyIdRef printfProp;
;~ JsGetPropertyIdFromName(L"printf", &printfProp);
    local $printfProp
    $printfProp=_JsGetPropertyIdFromName("printf", $printfProp)

;~ JsValueRef printfFunc;
;~ JsCreateFunction(PrintFormat, nullptr, &printfFunc);
    local $printfFunc
    $printfFunc=_JsCreateFunction(DllCallbackGetPtr($hPrintf),0,$printfFunc)

;~ JsSetProperty(nativeObj, printfProp, printfFunc, true);
_JsSetProperty($nativeObj,$printfProp,$printfFunc,true)

;~ JsSetProperty(global, nativeProp, nativeObj, true);
_JsSetProperty($global,$nativeProp,$nativeobj,true)

;~ STDAPI_(JsErrorCode) JsCreateFunction(
;~    _In_ JsNativeFunction nativeFunction,
;~    _In_opt_ void *callbackState,
;~    _Out_ JsValueRef *function
;~ );

; Get a JsValueRef for our Host object
;~ hostRef := ToJsValue(Host)
;~ $aResult=DllCall($hJSRuntime, "int","JsVariantToValue", "ptr", &variant, "ptr*", valref)
; Pass our Host object to the script engine
;~ DllCall("jscript9\JsSetProperty", "ptr", globalObject, "ptr", hostPropertyId, "ptr", hostRef, "int", true)

;~     // Run the script.
;~ STDAPI_(JsErrorCode) JsRunScript(
;~    _In_z_ const wchar_t *script,
;~    _In_ JsSourceContext sourceContext,
;~    _In_z_ const wchar_t *sourceUrl,
;~    _Out_ JsValueRef *result
;~ );
    local $currentSourceContext=1

;~     JsRunScript(script.c_str(), currentSourceContext++, L"", &result);
    local $result=""
    local $sourceURL=""
    $aResult=DllCall($hJSRuntime, "int", "JsRunScript", "WSTR", $script, "UINT*",$currentSourceContext, "wstr", "dummysource.js", "WSTR*", $result)
    consolewrite("Error 11: " & @error & @CRLF)
    if @error=0 Then
        consolewrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] &  ";" & $aResult[3] &  ";" & $aResult[4] & @CRLF)

    EndIf

;~ // Convert your script result to String in JavaScript redundant if your script returns a String
;~     JsValueRef resultJSString;
;~ STDAPI_(JsErrorCode) JsConvertValueToString(
;~    _In_ JsValueRef value,
;~    _Out_ JsValueRef *stringValue
;~ );
;~     JsConvertValueToString(result, &resultJSString);
;~  $aResult=DllCall($hJSRuntime, "int", "JsConvertValueToString", "WSTR", $script, "long", 1, "WSTR*",0, "WSTR*", $result)
;~  consolewrite("Error 4: " & @error & @CRLF)
;~  if @error=0 Then
;~      consolewrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] &  ";" & $aResult[3] &  ";" & $aResult[4] & @CRLF)
;~  EndIf
;~
;~     // Project script result back to C++.
;~     const wchar_t *resultWC;
;~     size_t stringLength;
;~     JsStringToPointer(resultJSString, &resultWC, &stringLength);

;~     wstring resultW(resultWC);
;~     cout << string(resultW.begin(), resultW.end()) << endl;
;~     system("pause");

;~     // Dispose runtime
;~     JsSetCurrentContext(JS_INVALID_REFERENCE);
;~     JsDisposeRuntime(runtime);

    return 0;


EndFunc   ;==>Example



; Create callback function.
;~ JsValueRef CALLBACK PrintFormat(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
;~ {
;~  const wchar_t *format;
;~  size_t length;
;~  JsStringToPointer(arguments[1], &format, &length);

;~  VARIANT variant;
;~  JsValueToVariant(arguments[2], &variant);

;~  const wchar_t *str;
;~  JsStringToPointer(arguments[3], &str, &length);

;~  wprintf(format, variant.intVal, str);

;~  return JS_INVALID_REFERENCE;
;~ }
;~ typedef _Ret_maybenull_ JsValueRef (CALLBACK * JsNativeFunction)(
;~    _In_ JsValueRef callee,
;~    _In_ bool isConstructCall,
;~    _In_ JsValueRef *arguments,
;~    _In_ unsigned short argumentCount
;~ );

func _printf($callee, $isConstructCall, $arguments, $argumentCount, $callbackState)
    consolewrite("there we are with " & $argumentCount & " arguments" & @CRLF)


;~  STDAPI_(JsErrorCode) JsConvertValueToString(
;~    _In_ JsValueRef value,
;~    _Out_ JsValueRef *stringValue
;~ );
    ;~     JsConvertValueToString(result, &resultJSString);
    local $tresult
    $aResult=DllCall($hJSRuntime, "int", "JsConvertValueToString", "ptr", $arguments[0], "ptr*", $tresult)
    consolewrite("Error 4: " & @error & @CRLF)
    if @error=0 Then
        consolewrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] & @CRLF)
        $tresult=$aresult[2]
    EndIf

;~ STDAPI_(JsErrorCode) JsValueToVariant(
;~    _In_ JsValueRef object,
;~    _Out_ VARIANT *variant
;~ );
    Local $aResult = DllCall($hJSRuntime, "dword", "JsValueToVariant", "ptr", $arguments[0], "ptr*", 0)
    If @error Then Return SetError(3, 0, @error)
    If $aResult[0] <> 0 Then Return SetError(4, 0, $aResult[0])
    consolewrite($aResult[2])

;~  Local $aResult = DllCall($hJSRuntime, "dword", "JsStringToPointer", "ptr", $tResult, "ptr*", 0, "int*", 0)
;~  If @error Then Return SetError(3, 0, @error)
;~  If $aResult[0] <> 0 Then Return SetError(4, 0, $aResult[0])

;~  Local $tString = DllStructCreate("wchar string["&$aResult[3]&"]", $aResult[2])
;~  consolewrite($tString.string)




    return 0
EndFunc


;~ typedef void *JsRuntimeHandle;
;~  // Create a runtime.
;~  Edge mode signature STDAPI_(JsErrorCode) JsCreateRuntime(
;~    _In_ JsRuntimeAttributes attributes,
;~    _In_opt_ JsThreadServiceCallback threadService,
;~    _Out_ JsRuntimeHandle *runtime);
;~ Legacy mode signature
;~ STDAPI_(JsErrorCode) JsCreateRuntime(
;~    _In_ JsRuntimeAttributes attributes,
;~    _In_ JsRuntimeVersion version,
;~    _In_opt_ JsThreadServiceCallback threadService,
;~    _Out_ JsRuntimeHandle *runtime
;~ );
;~  $runtime=_JsCreateRuntime(JsRuntimeAttributeNone, 0, $runtime);
func _JsCreateRuntime($JsRuntimeAttributeNone, $JSRuntimeVersion, $runtime)
    $aResult=DllCall($hJSRuntime, "int", "JsCreateRuntime", "int", $JsRuntimeAttributeNone, "int", $JsRuntimeVersion, "ptr", 0, "ptr*", $runtime)
    If @error Then Return SetError(1, @error, 0)
    Return $aresult[4]
EndFunc

;~ // Edge mode signature
;~ STDAPI_(JsErrorCode) JsCreateContext(
;~    _In_ JsRuntimeHandle runtime,
;~    _Out_ JsContextRef *newContext);

;~ // Legacy mode signature
;~ STDAPI_(JsErrorCode) JsCreateContext(
;~    _In_ JsRuntimeHandle runtime,
;~    _In_ IDebugApplication *debugApplication,
;~    _Out_ JsContextRef *newContext
;~ );
;~      JsCreateContext(runtime, &context);
func _JsCreateContext($runtime, $context)
    $aResult=DllCall($hJSRuntime, "int", "JsCreateContext",  "ptr", $runtime, "ptr",   0 , "ptr*", $context)
    If @error Then Return SetError(1, @error, 0)
    Return $aresult[3]
endfunc

;~ STDAPI_(JsErrorCode) JsSetCurrentContext(
;~    _In_ JsContextRef context
;~ );
;~     JsSetCurrentContext(context);
func _JsSetCurrentContext($context)
    $aResult=DllCall($hJSRuntime, "int", "JsSetCurrentContext", "ptr", $context)
    If @error Then Return SetError(1, @error, 0)
    Return $JsNoError
EndFunc

; Get the Global object for adding stuff
;~ STDAPI_(JsErrorCode) JsGetGlobalObject(
;~    _Out_ JsValueRef *globalObject
;~ );
;~ JsValueRef global;
;~ JsGetGlobalObject(&global);
func _JsGetGlobalObject($global)
    $aResult=DllCall($hJSRuntime, "int","JsGetGlobalObject", "ptr*", $global)
    If @error Then Return SetError(1, @error, 0)
    Return $aresult[1]
endfunc

; Get a property ID for the name "host"
;~ STDAPI_(JsErrorCode) JsGetPropertyIdFromName(
;~    _In_z_ const wchar_t *name,
;~    _Out_ JsPropertyIdRef *propertyId
;~ );
;~ DllCall("jscript9\JsGetPropertyIdFromName", "wstr", "host", "ptr*", hostPropertyId)
;~ local $hostPropertyID
;~ $aResult=DllCall($hJSRuntime, "int","JsGetPropertyIdFromName", "wstr", "host", "ptr*", $hostPropertyId)
;~  consolewrite("Error 5: " & @error & @CRLF)
;~  if @error=0 Then
;~      consolewrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2]  & @CRLF)
;~  EndIf


;~ JsPropertyIdRef nativeProp;
;~ JsGetPropertyIdFromName(L"native", &nativeProp);
func _JsGetPropertyIdFromName($propname, $nativeProp)
    $aResult=DllCall($hJSRuntime, "int","JsGetPropertyIdFromName", "wstr", $propname, "ptr*", $nativeProp)
    If @error Then Return SetError(1, @error, 0)
    Return $aresult[2]
endfunc

;~ STDAPI_(JsErrorCode) JsCreateObject(
;~    _Out_ JsValueRef *object
;~ );
;~ JsValueRef nativeObj;
;~ JsCreateObject(&nativeObj);
local $nativeObj
func _JsCreateObject($JSRTobject)
    $aResult=DllCall($hJSRuntime, "int","JsCreateObject", "ptr*", $JSRTObject)
    If @error Then Return SetError(1, @error, 0)
    return $aresult[1]
EndFunc

;~ STDAPI_(JsErrorCode) JsCreateFunction(
;~    _In_ JsNativeFunction nativeFunction,
;~    _In_opt_ void *callbackState,
;~    _Out_ JsValueRef *function
;~ );
func _JsCreateFunction($fncCallBackPtr,$callBackState,$fncVar)
    $aResult=DllCall($hJSRuntime, "int","JsCreateFunction", "ptr", $fncCallBackPtr, "ptr*", $callBackState, "ptr*", $fncVar)
    If @error Then Return SetError(1, @error, 0)
    return $aresult[3]
endfunc

;~ JsSetProperty(nativeObj, printfProp, printfFunc, true);
;~ STDAPI_(JsErrorCode) JsSetProperty(
;~    _In_ JsValueRef object,
;~    _In_ JsPropertyIdRef propertyId,
;~    _In_ JsValueRef value,
;~    _In_ bool useStrictRules
;~ );
func _JsSetProperty($Obj, $Prop, $Func, $val);
    $aResult=DllCall($hJSRuntime, "int","JsSetProperty", "ptr", $Obj, "ptr", $Prop, "ptr", $Func, "int", $val)
    If @error Then Return SetError(1, @error, 0)
EndFunc

 

Share this post


Link to post
Share on other sites

You need to create a structure of ptr array. Then get the value.

 

;~ https://iobservable.net/blog/2013/11/
;~ Should work on all windows versions with IE11

#AutoIt3Wrapper_UseX64=N
#Region enum JsErrorCode : unsigned int
Enum $JsNoError = 0, _
        $JsErrorCategoryUsage = 0x10000, _
        $JsErrorInvalidArgument, _
        $JsErrorNullArgument, _
        $JsErrorNoCurrentContext, _
        $JsErrorInExceptionState, _
        $JsErrorNotImplemented, _
        $JsErrorWrongThread, _
        $JsErrorRuntimeInUse, _
        $JsErrorBadSerializedScript, _
        $JsErrorInDisabledState, _
        $JsErrorCannotDisableExecution, _
        $JsErrorHeapEnumInProgress, _
        $JsErrorArgumentNotObject, _
        $JsErrorInProfileCallback, _
        $JsErrorInThreadServiceCallback, _
        $JsErrorCannotSerializeDebugScript, _
        $JsErrorAlreadyDebuggingContext, _
        $JsErrorAlreadyProfilingContext, _
        $JsErrorIdleNotEnabled, _
        $JsErrorCategoryEngine = 0x20000, _
        $JsErrorOutOfMemory, _
        $JsErrorCategoryScript = 0x30000, _
        $JsErrorScriptException, _
        $JsErrorScriptCompile, _
        $JsErrorScriptTerminated, _
        $JsErrorScriptEvalDisabled, _
        $JsErrorCategoryFatal = 0x40000, _
        $JsErrorFatal
;~    }JsErrorCode;
#EndRegion enum JsErrorCode : unsigned int
#Region    typedef enum JsRuntimeVersion
Enum $JsRuntimeVersion10 = 0, $JsRuntimeVersion11 = 1
#EndRegion typedef enum JsRuntimeVersion

; Create callback function.
Local $hPrintf = DllCallbackRegister("_printf", "long", "ptr;bool;ptr;ushort;ptr")
Local $hJSRuntime = DllOpen("c:\windows\system32\jscript9.dll")
$JsRuntimeAttributeNone = 0x00000000

;~ #RequireAdmin
Example()

Func Example()

    Local $script = "native.printf('hello world')"
;~  Local $script = "native.printf('number=%#x string=%s\n', 255, 'test')"

;~  Local $script = "(()=>{return 'Hello world!';})()"
;~  Local $script = "var x='helloworld'; return x;"
;~  Local $script = "var x=10;" & @CRLF & "var y=11;"
;~  Local $script = "(42);"
;~ Local $script = "(" & @CRLF
;~ $script=$script & "host.echo(JSON.stringify({foo:'bar'}));)" & @CRLF
;~ $script=$script & "42 // The script's result :) "& @CRLF
;~ $script=$script & ")"& @CRLF
;~ $script=$script & "class Host {"& @CRLF
;~ $script=$script & "    echo(s) {"& @CRLF
;~ $script=$script & "        MsgBox %s%"& @CRLF
;~ $script=$script & "    }"& @CRLF
;~ $script=$script & "}"& @CRLF

    Local $aResult
    Local $runtime
    Local $context

;~  // Create a runtime
;~      JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &runtime);
    $runtime = _JsCreateRuntime($JsRuntimeAttributeNone, 0, $runtime) ;

;~  // Create an execution context.
;~      JsCreateContext(runtime, &context);
    $context = _JsCreateContext($runtime, $context)

;~     // Now set the current execution context.
;~     JsSetCurrentContext(context);
    _JsSetCurrentContext($context) ;

    ; Get the Global object for adding stuff
;~ JsGetGlobalObject(&global);
    Local $global
    $global = _JsGetGlobalObject($global)

;~ JsPropertyIdRef nativeProp;
;~ JsGetPropertyIdFromName(L"native", &nativeProp);
    Local $nativeProp
    $nativeProp = _JsGetPropertyIdFromName("native", $nativeProp)

;~ JsValueRef nativeObj;
;~ JsCreateObject(&nativeObj);
    Local $nativeObj
    $nativeObj = _JsCreateObject($nativeObj)

;~ JsPropertyIdRef printfProp;
;~ JsGetPropertyIdFromName(L"printf", &printfProp);
    Local $printfProp
    $printfProp = _JsGetPropertyIdFromName("printf", $printfProp)

;~ JsValueRef printfFunc;
;~ JsCreateFunction(PrintFormat, nullptr, &printfFunc);
    Local $printfFunc
    $printfFunc = _JsCreateFunction(DllCallbackGetPtr($hPrintf), 0, $printfFunc)

;~ JsSetProperty(nativeObj, printfProp, printfFunc, true);
    _JsSetProperty($nativeObj, $printfProp, $printfFunc, True)

;~ JsSetProperty(global, nativeProp, nativeObj, true);
    _JsSetProperty($global, $nativeProp, $nativeObj, True)

;~ STDAPI_(JsErrorCode) JsCreateFunction(
;~    _In_ JsNativeFunction nativeFunction,
;~    _In_opt_ void *callbackState,
;~    _Out_ JsValueRef *function
;~ );

    ; Get a JsValueRef for our Host object
;~ hostRef := ToJsValue(Host)
;~ $aResult=DllCall($hJSRuntime, "int","JsVariantToValue", "ptr", &variant, "ptr*", valref)
    ; Pass our Host object to the script engine
;~ DllCall("jscript9\JsSetProperty", "ptr", globalObject, "ptr", hostPropertyId, "ptr", hostRef, "int", true)

;~     // Run the script.
;~ STDAPI_(JsErrorCode) JsRunScript(
;~    _In_z_ const wchar_t *script,
;~    _In_ JsSourceContext sourceContext,
;~    _In_z_ const wchar_t *sourceUrl,
;~    _Out_ JsValueRef *result
;~ );
    Local $currentSourceContext = 1

;~     JsRunScript(script.c_str(), currentSourceContext++, L"", &result);
    Local $result = ""
    Local $sourceURL = ""
    $aResult = DllCall($hJSRuntime, "int", "JsRunScript", "WSTR", $script, "UINT*", $currentSourceContext, "wstr", "dummysource.js", "WSTR*", $result)
    ConsoleWrite("Error 11: " & @error & @CRLF)
    If @error = 0 Then
        ConsoleWrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] & ";" & $aResult[3] & ";" & $aResult[4] & @CRLF)

    EndIf

;~ // Convert your script result to String in JavaScript redundant if your script returns a String
;~     JsValueRef resultJSString;
;~ STDAPI_(JsErrorCode) JsConvertValueToString(
;~    _In_ JsValueRef value,
;~    _Out_ JsValueRef *stringValue
;~ );
;~     JsConvertValueToString(result, &resultJSString);
;~  $aResult=DllCall($hJSRuntime, "int", "JsConvertValueToString", "WSTR", $script, "long", 1, "WSTR*",0, "WSTR*", $result)
;~  consolewrite("Error 4: " & @error & @CRLF)
;~  if @error=0 Then
;~      consolewrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] &  ";" & $aResult[3] &  ";" & $aResult[4] & @CRLF)
;~  EndIf
;~
;~     // Project script result back to C++.
;~     const wchar_t *resultWC;
;~     size_t stringLength;
;~     JsStringToPointer(resultJSString, &resultWC, &stringLength);

;~     wstring resultW(resultWC);
;~     cout << string(resultW.begin(), resultW.end()) << endl;
;~     system("pause");

;~     // Dispose runtime
;~     JsSetCurrentContext(JS_INVALID_REFERENCE);
;~     JsDisposeRuntime(runtime);

    Return 0 ;


EndFunc   ;==>Example



; Create callback function.
;~ JsValueRef CALLBACK PrintFormat(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
;~ {
;~  const wchar_t *format;
;~  size_t length;
;~  JsStringToPointer(arguments[1], &format, &length);

;~  VARIANT variant;
;~  JsValueToVariant(arguments[2], &variant);

;~  const wchar_t *str;
;~  JsStringToPointer(arguments[3], &str, &length);

;~  wprintf(format, variant.intVal, str);

;~  return JS_INVALID_REFERENCE;
;~ }
;~ typedef _Ret_maybenull_ JsValueRef (CALLBACK * JsNativeFunction)(
;~    _In_ JsValueRef callee,
;~    _In_ bool isConstructCall,
;~    _In_ JsValueRef *arguments,
;~    _In_ unsigned short argumentCount
;~ );

Func _printf($callee, $isConstructCall, $arguments, $argumentCount, $callbackState)
    ConsoleWrite("there we are with " & $argumentCount & " arguments" & @CRLF)


    Local $tArgs = DllStructCreate("ptr JsValues[" & $argumentCount & "]", $arguments)
;~  STDAPI_(JsErrorCode) JsConvertValueToString(
;~    _In_ JsValueRef value,
;~    _Out_ JsValueRef *stringValue
;~ );
;~     JsConvertValueToString(result, &resultJSString);
    local $tresult
    $aResult=DllCall($hJSRuntime, "int", "JsConvertValueToString", "ptr", DllStructGetData($tArgs,1,2), "ptr*", $tresult)
    consolewrite("Error 4: " & @error & @CRLF)
    if @error=0 Then
        consolewrite( $aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] & @CRLF)
        $tresult=$aresult[2]
    EndIf

;~ STDAPI_(JsErrorCode) JsValueToVariant(
;~    _In_ JsValueRef object,
;~    _Out_ VARIANT *variant
;~ );
;~     Local $aResult = DllCall($hJSRuntime, "dword", "JsValueToVariant", "ptr", $arguments[0], "ptr*", 0)
;~     If @error Then Return SetError(3, 0, @error)
;~     If $aResult[0] <> 0 Then Return SetError(4, 0, $aResult[0])
;~     consolewrite($aResult[2])

 Local $aResult = DllCall($hJSRuntime, "dword", "JsStringToPointer", "ptr", $tResult, "ptr*", 0, "int*", 0)
 If @error Then Return SetError(3, 0, @error)
 If $aResult[0] <> 0 Then Return SetError(4, 0, $aResult[0])

 Local $tString = DllStructCreate("wchar string["&$aResult[3]&"]", $aResult[2])
 consolewrite("+Parameter: " & $tString.string & @CRLF)




    Return 0
EndFunc   ;==>_printf


;~ typedef void *JsRuntimeHandle;
;~  // Create a runtime.
;~  Edge mode signature STDAPI_(JsErrorCode) JsCreateRuntime(
;~    _In_ JsRuntimeAttributes attributes,
;~    _In_opt_ JsThreadServiceCallback threadService,
;~    _Out_ JsRuntimeHandle *runtime);
;~ Legacy mode signature
;~ STDAPI_(JsErrorCode) JsCreateRuntime(
;~    _In_ JsRuntimeAttributes attributes,
;~    _In_ JsRuntimeVersion version,
;~    _In_opt_ JsThreadServiceCallback threadService,
;~    _Out_ JsRuntimeHandle *runtime
;~ );
;~  $runtime=_JsCreateRuntime(JsRuntimeAttributeNone, 0, $runtime);
Func _JsCreateRuntime($JsRuntimeAttributeNone, $JSRuntimeVersion, $runtime)
    $aResult = DllCall($hJSRuntime, "int", "JsCreateRuntime", "int", $JsRuntimeAttributeNone, "int", $JSRuntimeVersion, "ptr", 0, "ptr*", $runtime)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[4]
EndFunc   ;==>_JsCreateRuntime

;~ // Edge mode signature
;~ STDAPI_(JsErrorCode) JsCreateContext(
;~    _In_ JsRuntimeHandle runtime,
;~    _Out_ JsContextRef *newContext);

;~ // Legacy mode signature
;~ STDAPI_(JsErrorCode) JsCreateContext(
;~    _In_ JsRuntimeHandle runtime,
;~    _In_ IDebugApplication *debugApplication,
;~    _Out_ JsContextRef *newContext
;~ );
;~      JsCreateContext(runtime, &context);
Func _JsCreateContext($runtime, $context)
    $aResult = DllCall($hJSRuntime, "int", "JsCreateContext", "ptr", $runtime, "ptr", 0, "ptr*", $context)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[3]
EndFunc   ;==>_JsCreateContext

;~ STDAPI_(JsErrorCode) JsSetCurrentContext(
;~    _In_ JsContextRef context
;~ );
;~     JsSetCurrentContext(context);
Func _JsSetCurrentContext($context)
    $aResult = DllCall($hJSRuntime, "int", "JsSetCurrentContext", "ptr", $context)
    If @error Then Return SetError(1, @error, 0)
    Return $JsNoError
EndFunc   ;==>_JsSetCurrentContext

; Get the Global object for adding stuff
;~ STDAPI_(JsErrorCode) JsGetGlobalObject(
;~    _Out_ JsValueRef *globalObject
;~ );
;~ JsValueRef global;
;~ JsGetGlobalObject(&global);
Func _JsGetGlobalObject($global)
    $aResult = DllCall($hJSRuntime, "int", "JsGetGlobalObject", "ptr*", $global)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[1]
EndFunc   ;==>_JsGetGlobalObject

; Get a property ID for the name "host"
;~ STDAPI_(JsErrorCode) JsGetPropertyIdFromName(
;~    _In_z_ const wchar_t *name,
;~    _Out_ JsPropertyIdRef *propertyId
;~ );
;~ DllCall("jscript9\JsGetPropertyIdFromName", "wstr", "host", "ptr*", hostPropertyId)
;~ local $hostPropertyID
;~ $aResult=DllCall($hJSRuntime, "int","JsGetPropertyIdFromName", "wstr", "host", "ptr*", $hostPropertyId)
;~  consolewrite("Error 5: " & @error & @CRLF)
;~  if @error=0 Then
;~      consolewrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2]  & @CRLF)
;~  EndIf


;~ JsPropertyIdRef nativeProp;
;~ JsGetPropertyIdFromName(L"native", &nativeProp);
Func _JsGetPropertyIdFromName($propname, $nativeProp)
    $aResult = DllCall($hJSRuntime, "int", "JsGetPropertyIdFromName", "wstr", $propname, "ptr*", $nativeProp)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[2]
EndFunc   ;==>_JsGetPropertyIdFromName

;~ STDAPI_(JsErrorCode) JsCreateObject(
;~    _Out_ JsValueRef *object
;~ );
;~ JsValueRef nativeObj;
;~ JsCreateObject(&nativeObj);
Local $nativeObj
Func _JsCreateObject($JSRTobject)
    $aResult = DllCall($hJSRuntime, "int", "JsCreateObject", "ptr*", $JSRTobject)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[1]
EndFunc   ;==>_JsCreateObject

;~ STDAPI_(JsErrorCode) JsCreateFunction(
;~    _In_ JsNativeFunction nativeFunction,
;~    _In_opt_ void *callbackState,
;~    _Out_ JsValueRef *function
;~ );
Func _JsCreateFunction($fncCallBackPtr, $callbackState, $fncVar)
    $aResult = DllCall($hJSRuntime, "int", "JsCreateFunction", "ptr", $fncCallBackPtr, "ptr*", $callbackState, "ptr*", $fncVar)
    If @error Then Return SetError(1, @error, 0)
    Return $aResult[3]
EndFunc   ;==>_JsCreateFunction

;~ JsSetProperty(nativeObj, printfProp, printfFunc, true);
;~ STDAPI_(JsErrorCode) JsSetProperty(
;~    _In_ JsValueRef object,
;~    _In_ JsPropertyIdRef propertyId,
;~    _In_ JsValueRef value,
;~    _In_ bool useStrictRules
;~ );
Func _JsSetProperty($Obj, $Prop, $Func, $val) ;
    $aResult = DllCall($hJSRuntime, "int", "JsSetProperty", "ptr", $Obj, "ptr", $Prop, "ptr", $Func, "int", $val)
    If @error Then Return SetError(1, @error, 0)
EndFunc   ;==>_JsSetProperty

Saludos

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Colduction
      Hi AutoIt Scripters/Programmers. I have a question about MIME Tools for Notepad++:
      I've recently found a UDF about Base64 in forum, but they can't decode\encode correctly some emojis , other UTFs and etc. so i decided to use mimeTools.dll of Notepad++ or main site
      My problem is how to use this dll in AutoIt Language?

      I will be happy with your comments and answers❤ Thanks.
    • By FrancescoDiMuro
      Good morning Forums 
      In these days, I am working on a project that involved me to use some Windows APIs to obtain some information about Terminal Servers.
      I'm doing this using wtsapi32.dll in a VBA Project, but, the lack of knowledge about few things threated in the articles make this quite difficult to
      implement and understand at the same time.
      The most difficult thing I'm facing is "translating" C/C++ functions or struct in VBA when pointers are used, or pointers of pointers, and so on.
      Since VBA seems to not have a pointer type, to make those functions work I need to implement other functions taken from other DLLs, and this confuses me a lot.
      For example, starting from this code, I splitted all the functions and all the definitions to understand why they are there, and why I need to use them.
      At the end, I've found out that the code I was going to implement starting from the functions provided in the Microsoft Docs won't be ever be able to work without some supplementary functions which are not mentioned anywhere.
      So, I was wondering if someone would please point me out to a good and practical exaplanation about pointers (in general) or specifically for VBA, because I need to use them quite often in these days, and I'd like to understand what I am doing.
      Thanks in advance.

      Best Regards and Stay at home 🏡
       
    • By zuladabef
      All my scripts were working fine and now I am getting this error.  How do I resolve it?  Which folder(s) do the DLLs need to be in?
      ! Dll not found or Call Dll error !  
    • By RAMzor
      Hello all!
      I got the Acroname Programmable USB Hub based on BrainStem platform. I will use it to manage ports and read current.
      They have development kit (BRAINSTEM DEVELOPMENT KIT) with examples for any languages like C#, C++, LabVIEW and python but no AutoIt.
      The kit include BrainStem2.dll (x32 and x64), BrainStem2_LabVIEW.dll, BrainStem2CLI.dll and many examples.
      Anyone used this dll and implemented it in AutoIt?
      Please share some example for Device Discovering, User LED Flashing or power enable/disable on port to start play with this HUB
      BrainStem Reference 
       
      BrainStem2 lib+example.7z USB HUB User Manual s79-usbhub-3p_v1.10_0.pdf
    • By matwachich
      Hi guys!
      A pretty simple UDF to convert HTML to PDF using wkHTMLtoPDF.
      It uses the C API of the tool (DLL), so no external process, no ActiveX or COM sh*t.
      See the example, and the documentation of wkHTMLtoPDF.
      Cheers
      https://github.com/matwachich/wkhtmltopdf-au3
×
×
  • Create New...