Re: Parameterized js functions using js-ctypes.

Benjamin Smedberg <[email protected]> Thu, 08 May 2014 09:21:19 -0400
Newsgroups gmane.comp.mozilla.devel.plugins
Message-ID <[email protected]>
On 5/8/2014 7:33 AM, Girish Gaitonde wrote:
> 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