Discussion:
Parameterized js functions using js-ctypes.
Girish Gaitonde
2014-05-08 11:33:54 UTC
Permalink
Hi,

We are currently working on changing NPAPI based extension,to js-ctypes.

I want my "C" based function [dll], to access js function.

Till now we had success in calling js function which don't have parameters.

But now we need to send some data from dll, to js function.

Below is the prototype

var funcType = ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t,
[ctypes.voidptr_t]);
var funcPtrType = funcType.ptr;
var callback = funcPtrType(receiveMessage);
var ret = Wr_Request(JSON.stringify(data),callback);


js function
function receiveMessage()
{
var MB_OK = 3;
var ret_msgbo = msgBox(0, "Hello world" +
temp_char.address().readString(), "title", MB_OK);
};

Can anybody help out with this??
Benjamin Smedberg
2014-05-08 13:21:19 UTC
Permalink
Post by Girish Gaitonde
But now we need to send some data from dll, to js function.
Below is the prototype
var funcType = ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t,
[ctypes.voidptr_t]);
var funcPtrType = funcType.ptr;
var callback = funcPtrType(receiveMessage);
var ret = Wr_Request(JSON.stringify(data),callback);
js function
function receiveMessage()
{
var MB_OK = 3;
var ret_msgbo = msgBox(0, "Hello world" +
temp_char.address().readString(), "title", MB_OK);
};
mozilla.dev.extensions is the better list for questions about ctypes:
please follow up there.

It seems that you are declaring your callback function with a void*
parameter. It looks like you're passing it a string and this should be a
char* (ctypes.char.ptr) or maybe a windows wchar* which is equivalent to
a ctypes.jschar.ptr.

The JS function doesn't have any declared parameters at all, which is
strange. I would expect it to be something like this:

function receiveMessage(str) {
// do something with `str`
}

Also, if "msgBox" is the Windows MessageBox function, please don't do
that. Modal dialogs are bad design in general, but MessageBox blocks the
Firefox event loop and can lead to severe performance problems and
memory starvation. Please use standard Mozilla UI elements such as
window.showModalDialog or even better, make a non-modal UI.

--BDS
Girish Gaitonde
2014-05-08 14:07:20 UTC
Permalink
Thanks for guiding :)

Loading...