JSctypes: Difference between revisions

Jump to navigation Jump to search
280 bytes removed ,  13 October 2009
no edit summary
No edit summary
Line 16: Line 16:


<pre>
<pre>
const nsINativeTypes = Components.interfaces.nsINativeTypes;
/* Load JS Ctypes Javascript module */
const MB_OK = 3;
Components.utils.import("resource://gre/modules/ctypes.jsm");
var Types = ctypes.types;
function messageBox() {
  // create the XPCOM js-ctypes instance
  var library = Components.classes["@developer.mozilla.org/js-ctypes;1"]
                          .createInstance(nsINativeTypes);


  // load the native shared library
/* Load windows api dll */
  library.open("user32.dll");
var lib = ctypes.open("C:\\WINDOWS\\system32\\user32.dll");


  // declare the native method
/* Declare the signature of the function we are going to call */
  var msgBox = library.declare("MessageBoxW",           /* function name */
var msgBox = lib.declare("MessageBoxW",
                              nsINativeTypes.STDCALL, /* call type */
                        ctypes.stdcall_abi,
                              nsINativeTypes.INT32,   /* return type */
                        ctypes.int32_t,
                              nsINativeTypes.INT32,   /* arg 1 */
                        ctypes.int32_t,
                              nsINativeTypes.WSTRING, /* arg 2 */
                        ctypes.ustring,
                              nsINativeTypes.WSTRING, /* arg 3 */
                        ctypes.ustring,
                              nsINativeTypes.INT32);   /* arg 4 */
                        ctypes.int32_t);
var MB_OK = 3;


  // call the native method
/* Do it! */
  var ret = msgBox(0, "This is the coolest message", "My Title", MB_OK);
var ret = msgBox(0, "Hello world", "title", MB_OK);


  // test the return value
/* Display the returned value */
  alert(ret);
alert("MessageBox result : "+ret);
}
 
lib.close();
</pre>
</pre>


20

edits

Navigation menu