[Prev] Thread [Next]  |  [Prev] Date [Next]

JS-Ctype issues chrisw Mon Feb 13 15:01:04 2012


I am trying to develop a DLL/dylib binary extension using JS-CTypes to
explore the capabilities of the technology for potential use in our

Our products run on all the major browsers, and under Firefox, we
support the latest 3 versions of Firefox on both Windows and OSX.
Most of our product has and most likely will continue to be contained
within a binary library.  Currently we use XPCOM to manage the
interface between script and C++ and for the most part it work as we
need it.  Our plugin implementation currently passes objects between
JS and C++ which allows us to keep a high degree of protection on a
individuals personal data while they use our product to interact with
our customers web pages and we do not intend to change this any time

To try out JS-CTypes I have written a test toolbar extension that
should be working on the MAC and Windows environments.  Sadly, reality
is far different than the expected results.

* currently I have the test toolbar sample running on windows 7 in 32
bit mode, only.  64 bit still doesn't work, but I haven't tried
building mozilla-central in 64bit yet, so it may work.
* the same source code is used to compile a mac version, but while I
can load the dylib, I can not resolve any exported functions.

Getting back to what works:

so far I can write a DLL under win32 and expect to be able to send
data back and forth.  For the most part this is true, only as long as
you use simple data types (ints, doubles, bools, etc)

Strings don't work very well because they are inherently JS objects.
It is somewhat easy to create a compatible ctype.char or ctype.wchar
string and use those, but they really only work well when you have
static string buffers or any static length string or char arrays.

I still have not been able to get pointers to work.  Try and pass any
arguments that contain void pointers and it just fails.  I can return
a void pointer from a function, but all you get is a JSON
representation of the address of the pointer which is not that useful
in JS.

If anyone has some ideas on what I need to look at when using JS-
CTypes on the MAC, that would be most appreciated.  Even some better
sample code would be nice.  I am looking for anything that
demonstrates not only the creation of the library in C++ but the code
that calls it from JS.

I can get the win32 32bit code to work as expected, but I have not
seen any results on the mac yet.

Either way, in my experience it is much harder to write a good cross
platform binary extension using JS-Ctypes and C++ than it is with
XPCOM and C++.

dev-extensions mailing list