Developing NokSync

NokSync on SourceForge

NokSync is hosted by SourceForge, where you may download the latest release, or access the Subversion repository directly.

There is also a Developers Discussion Forum, and a number of Trackers for bug reporting, patches, etc.

NokSync Design

NokSync is a Thunderbird extension.
As such it consists of JavaScript (.js) and XML User Interface Language (.xul) files.
The JavaScript calls an XPCOM component called noksyncDLL,
which again calls COM componens from the "Nokia PC suite".


Contents of the NokSync Directory

The interface for the XPCOM DLL (noksync.dll) is defined in INokSync.idl

The main window functionality is defined in main.js_

Building a responsive GUI

When NokSync is running, we want

The first solution which comes to mind is to use threads in the .dll.
However, XPCOM threading seems to be quite difficult, and not well documented.
Moreover, the functions in the Nokia PC Suite .dll's are quite "atomic"; i.e. checking for whether a phone is connected returns "immediatly" with "yes" or "no", and reading contacts and appointments is "one-by-one". So, unless something in the Nokia PC Suite is severely broken, it should actually be quite responsive.

So, a better solution would be to implement threads or asynchronous messaging in JavaScript.
However, it does not seem that threading is possible from JavaScript - at least it does not seem to be documented at all.
Further, messaging in Mozilla seems always to be synchronous. E.g. trying commandDispatcher or creating a new window and using dispatchEvent both works synchronously.

The solution? Well, in NokSync we use a timer: windows.setTimeout(), e.g.

	window.setTimeout(stepPreferences, 0);
This will release the current thread to check on the GUI, and as soon as possible call the stepPreferences function.

NokSync Error Handling

You must catch all C++ exceptions! Exceptions in dll's will crash Thunderbird.
In NokSync, this is implemented with the macros:

nsresult, hResult and nmpResult in NokSync

Most methods in NokSync are defined like this:
	void someMethod(otherargs..., inout long hResult, inout long nmpResult);

If the windows com system returns a HRESULT failure, the value is returned in hResult.

If the error ultimatly originated in the NMP DLL library, nmpResult will be set to the NmpAdapterError returned.

In both of the above cases, NS_ERROR_UNEXPECTED will be returned as the nsresult return value.

Other C++ exceptions will not return a specific error code.

A textual description of the error can usually be found using GetLastErrorString.

See also:
inout parameters in XPCOM IDL / JavaScript

Hints about Thunderbird and Extensions

Building a Thunderbird extension

The canonical resource is and a good tutorial can be found at

However, for XUL the best resource is

And a JavaScript reference:

You may also want reload of the chrome: although NokSync development works fine without.

The Thunderbird Addressbook

The Thunderbird addressbook is documented at

You may also want to take a look at another addressbook synchronization extension:

Building an XPCOM component

Official tutorial:

You must have the Gecko SDK.

Some libraries (e.g. libIDL-0.6.dll) are missing in Gecko SDK, so you will also need:

How to access a component:

Browsing installed components should be possible with but I can not get it to work

xpi and registering with regxpcom

Components should be registered with regxpcom. But I could not get it to work:

..\regxpcom.exe  -x . INokSync.xpt
Can not initialize XPCOM Glue
Can not aquire component registrar
Registration failed: (c1f30001) INokSync.xpt

So here is the cool solution: Just copy the .dll and .xpt file in the extensions/components directory, and it works like a charm!

inout parameters in XPCOM IDL / JavaScript

Parameters defined as inout in IDL must be initialized as new Object(); in JavaScript before calling.

For example, myFunction defined in xidl:

	void myFunction(inout long x);

must be called from JavaScript as:

	var myX=new Object();

Nokia PC Suite

The canonical interface for NOKIA phones is the Nokia PC Suite (
However, there are two problems:

Bluetooth through Java

Trying to overcome the two problems, I wanted to implement an interface to (NOKIA) phones over Bluetooth using Java.

There is a standard for such things: JSR-82 (
... and there is even implementations which can be downloaded. For example from Sun, as described at
... but this is now only for unix!!!
Anyway there is an implementation somewhere

The problem is, that JSR-82 relies on a transport mechanism, which is not standardized. I could not get UARTTransport (the default with Sun) to work. Also tried RXTXcomm ( and could not get it to work.

So, back to Nokia PC Suite...

Nokia PC Suite and Thunderbird

When Nokia PC Suite is installed, it comes with a few nice .dll's, such as:

The documentation can be downloaded here:

Bad news (1): Only for Windows

As described above (Bluetooth through Java), I could not get a generic Bluetooth interface through Java to work, so we are stuck with Nokia PC Suite.
And since Nokia PC Suite is only available for Microsoft Windows, NokSync will only work on Microsoft Windows.
(What a shame, considering that Thunderbird and XPCOM is cross platform)

Bad news (2): Not for all NOKIA phones

There are many different NOKIA phones with different capabilities, and NOKIA - in their wisdom - has implemented different interfaces for different phones.

Since my phone is a NOKIA 6280, NokSync is using the IPhonebook3 and IContact2 interfaces.

NOKIA is not very clear on which phones are supported by the IPhonebook3 and IContact2 interfaces in the SCM3aS.dll library used by NokSync. The official statement from year 2002 is, that series 62xx and 71xx are supported.

If the NOKIA phone can store more than one phone number per contact (such as both a cellular number and a landline number), there is a good chance that NokSync will work with the phone.

Whether it works or not, please be so kind as to report your model number and product type on the Open Discussion Forum.

Using doxygen

doxygen homepage:
Thank you Dimitri (

I was considering using doxygen just for the "code documentation", and using DocBook ( for the "main body" of documentation. There is a nice package for windows at
However, why waste time with this, when doxygen has it all?

doxygen and JavaScript

Native doxygen does not handle JavaScript.
However, there is a nice perl script at which can be downloaded at

Using doxygen for NokSync documentation

The html documentation is generated into the doc directory.

The documentation is generated from the (JavaScript, IDL, and C++) source code, plus the additional files in the dox subdirectory.

The dox subdirectory contains a doxygen.bat file which will call for .js files (generating an .js_ file) and then call doxygen.

The doxygen config file dox/Doxygen contains a few customizations; most importantly some EXPAND_AS_DEFINED to make the match between .idl, .h, and .cpp definitions.