All interfaces have the following initialization method that you must implement:
Init (nsISupports * aServer);
The server invokes this method immediately after it registers the interface in a newly loaded module. In the module, you can bind the parameter that the server returns, aServer, and use it to refer to the server instance. Your custom plug-in can use the QueryInterface method to find the server interfaces.
The following example checks the version of Calendar Server. It demonstrates how to do the following:
Bind the returned reference from the Init method.
Query the server for an interface.
Call a server method in that interface.
Release the server reference.
NS_IMETHODIMP csDataTranslator :: Init(nsISupports * aServer) { nsresult res = NS_COMFALSE ; PRUint32 min, maj; csICalendarServer * cs; /* QueryInterface for CalendarServer. If call succeeds, server increments reference count */ if (aServer) res = aServer-\>QueryInterface(kICalendarServerIID,(void**)&cs); /* If succeeded in getting reference to server, check version */ if (NS_SUCCEEDED(res)) { cs-\>GetVersion(maj,min); if (min \> 0 && maj \>= 1) res = NS_OK; else res = NS_COMFALSE; /* Release this reference to the server instance */ cs-\>Release(); } return res; }