元帅C#和Emscripten - 回调

时间:2015-02-13 14:09:03

标签: javascript c# interop marshalling emscripten

我正在尝试创建 C#方法并将其链接到现有的 JavaScript方法,但我在MarshalEmscripten方面遇到了一些问题用法。 我试图在代码中包含我的问题,因为它更容易理解。

这是javascript方法

// What are the types of those parameters ?
JS_WebRequest_SetHandler: function (request, arg, onresponse)
{
    var http = wr.requestInstances[request];
    http.onload = function http_onload(e) {
    // ...
    var byteArray = new Uint8Array(http.response);
    var buffer = _malloc(byteArray.length);
    HEAPU8.set(byteArray, buffer);
    Runtime.dynCall('viiii', onresponse, [arg, http.status, buffer, byteArray.length]);
    // ...
}

这是C#内容

// Are the types right ?
[DllImport("__Internal")]
private static extern void JS_WebRequest_SetHandler(int request, IntPtr arg, IntPtr onresponse);

public void SetHandler(string arg) // Example with a string
{
    // How can I link the OnResponse method to the JS_WebRequest_SetHandler onresponse ?
    // What types should I use ?
    JS_WebRequest_SetHandler(request, arg, onresponse);
}

// Are those types right ?
public void OnResponse(IntPtr arg, IntPtr status, IntPtr buffer, IntPtr length)
{
    // How can I extract the data of each argument ?
}

非常感谢

0 个答案:

没有答案