20
edits
MarkFinkle (talk | contribs) |
Kirschkern (talk | contribs) m (Updated the link to the devmo page) |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Note|This article is outdated. See the devmo pages for the current version.https://developer.mozilla.org/en/JavaScript_code_modules/ctypes.jsm}} | |||
== Overview == | == Overview == | ||
Line 16: | Line 18: | ||
<pre> | <pre> | ||
/* Load JS Ctypes Javascript module */ | |||
Components.utils.import("resource://gre/modules/ctypes.jsm"); | |||
/* Load windows api dll */ | |||
var lib = ctypes.open("C:\\WINDOWS\\system32\\user32.dll"); | |||
/* Declare the signature of the function we are going to call */ | |||
var msgBox = lib.declare("MessageBoxW", | |||
ctypes.stdcall_abi, | |||
ctypes.int32_t, | |||
ctypes.int32_t, | |||
ctypes.ustring, | |||
ctypes.ustring, | |||
ctypes.int32_t); | |||
var MB_OK = 3; | |||
/* Do it! */ | |||
var ret = msgBox(0, "Hello world", "title", MB_OK); | |||
/* Display the returned value */ | |||
alert("MessageBox result : "+ret); | |||
lib.close(); | |||
</pre> | |||
Instead of defining the whole path, you may also just give the file name. | |||
<pre> | |||
var lib = ctypes.open("user32.dll"); | |||
</pre> | |||
Or even without the extension. | |||
<pre> | |||
var lib = ctypes.open("user32"); | |||
</pre> | </pre> | ||
If the full path is not given, Windows uses the following search order to locate the DLL: | |||
#The current directory of the task that is using the DLL. | |||
#The \WINNT directory. | |||
#The \WINNT\SYSTEM directory. | |||
#The \WINNT\SYSTEM32 directory. | |||
#The directory of the executable for the task that is using the DLL. | |||
#A directory listed in the PATH environment variable. | |||
(taken from http://support.microsoft.com/kb/164501/) | |||
{{Note|This functionality cannot be accessed from JavaScript used in web content. Only JavaScript that runs with chrome privileges (extensions and Firefox UI for example) can use js-ctypes.}} | {{Note|This functionality cannot be accessed from JavaScript used in web content. Only JavaScript that runs with chrome privileges (extensions and Firefox UI for example) can use js-ctypes.}} | ||
Line 48: | Line 69: | ||
== Technical Notes and Limitations == | == Technical Notes and Limitations == | ||
The js-ctypes code uses the same [http://sourceware.org/libffi/ libffi] library as the Python ctypes module. It is currently known to work on Windows, Mac and Linux | The js-ctypes code uses the same [http://sourceware.org/libffi/ libffi] library as the Python ctypes module. It is currently known to work on Windows, Mac and Linux. | ||
== Getting the Code == | == Getting the Code == |
edits