The main objective for the library is to help developers avoid building binary (C++) XPCOM components when only a simple wrapper is needed. Such situations include:
- Developer wants functionality not built into the Mozilla platform, but easily supported by the native OS.
- Developer wants to use a 3rd party library in an extension or XUL app.
- Developer has methods in native code for performance reasons.
Instead of defining the whole path, you may also just give the file name.
var lib = ctypes.open("user32.dll");
Or even without the extension.
var lib = ctypes.open("user32");
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/)
Technical Notes and Limitations
The js-ctypes code uses the same libffi library as the Python ctypes module. It is currently known to work on Windows, Mac and Linux.
Getting the Code
The code can be checked out using Subversion:
svn co http://svn.mozilla.org/projects/js-ctypes/trunk/
It can also be viewed online here.
Until js-ctypes makes its way into the Mozilla tree, building it will be a bit of a chore.
You'll first want to check out and build the Mozilla tree. See the Build Documentation for information on how to do this. The rest of these instructions assume that the path to your mozilla tree source is called PATH_TO_MOZILLA and that your objdir is in PATH_TO_OBJDIR.
You'll first want to create a directory called PATH_TO_MOZILLA/toolkit/components/js-ctypes and put the svn checkout there.
Then, from your objdir root, run the following command:
This should build the necessary Makefiles in your objdir, creating directories as necessary.
Now enter the PATH_TO_OBJDIR/toolkit/components/js-ctypes directory and run make.
Once that's done, you should be able to enter PATH_TO_OBJDIR/dist/bin and use xpcshell to play around with the component (see the example usage code above).
Contributions are welcome! We have a Bugzilla component (see bugs, file bug). Please feel free to join #labs on irc.mozilla.org if you have any other questions.