I'm trying to experiment with getting the ChakraCore.dll to load on Windows with Golang but I'm having trouble figuring out what parameter type I need to pass in as the third parameter.
My assumption from reading the library code and loosely following the Embedding ChakraCore is that the third parameter needs to be a void pointer pointer (void**) as the header files define JsRuntimeHandle as typedef void *JsRuntimeHandle;
I'm hoping to avoid CGo if possible as well.
Console output:
panic: JsCreateRuntime failed: An argument to a hosting API was null in a context where null is not allowed. (JsErrorNullArgument)
Code:
package main
import (
"fmt"
"syscall"
"unsafe"
)
var (
chakraCore, _ = syscall.LoadLibrary("ChakraCore.dll")
jsCreateRuntime, _ = syscall.GetProcAddress(chakraCore, "JsCreateRuntime")
)
const (
JsNoError = 0
JsErrorNullArgument = 0x10002
)
const (
JsRuntimeAttributeNone = 0x00000000
)
func main() {
const functionName = "JsCreateRuntime"
var runtime uintptr
ret, _, err := syscall.Syscall(
uintptr(jsCreateRuntime),
3,
uintptr(JsRuntimeAttributeNone),
uintptr(0),
uintptr(unsafe.Pointer(runtime)),
)
if err != 0 {
panic(fmt.Sprintf("%s failed: %v", functionName, err))
}
switch (ret) {
case JsNoError:
break
case JsErrorNullArgument:
panic(fmt.Sprintf("%s failed: An argument to a hosting API was null in a context where null is not allowed. (JsErrorNullArgument)", functionName))
default:
panic(fmt.Sprintf("%s failed: Unhandled error kind (%v).", functionName, ret))
}
panic(fmt.Sprintf("runtime: %v | ret: %v\n", runtime, uint(ret)))
return
}
I might have gotten something wrong here, but when I just ignore the error that Windows is giving me and keep going, everything seems to execute fine.
For example, if I run this:
I get the following output in console: