rv = NS_InitXPCOM(&servMgr, NULL, NULL);
rv = NS_InitXPCOM(&servMgr, NULL);
int main( int argc, char *argv[] ) {#ifdef __MWERKS__	// Hack in some arguments.  A NULL registry name is supposed to tell libreg	// to use the default registry (which does seem to work).	argc = 2;	const char* myArgs[] =	{		"regExport"	,	NULL	};	argv = const_cast<char**>(myArgs);#endif    nsresult rv;    // Initialize XPCOM    nsIServiceManager *servMgr = NULL;    rv = NS_InitXPCOM(&servMgr, NULL, NULL);    if (NS_FAILED(rv))    {        // Cannot initialize XPCOM        printf("Cannot initialize XPCOM. Exit. [rv=0x%08X]\n", (int)rv);        exit(-1);    }    // Get the component manager    static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);    nsCOMPtr<nsIComponentManager> compMgr = do_GetService(kComponentManagerCID, &rv);    if (NS_FAILED(rv))    {        // Cant get component manager        printf("Cannot get component manager from service manager.. Exit. [rv=0x%08X]\n", (int)rv);        exit(-1);    }    // Create the registry    nsIRegistry *reg;    rv = compMgr->CreateInstanceByProgID(NS_REGISTRY_PROGID, NULL,                                         NS_GET_IID(nsIRegistry),                                         (void **) &reg);    // Check result.    if ( NS_FAILED(rv) )    {           printf( "Error opening registry file %s, rv=0x%08X\n", argv[1] ? argv[1] : "<default>", (int)rv );        return rv;    }        // Open it against the input file name.    rv = reg->Open( argv[1] );        if ( rv == NS_OK ) {        NS_ADDREF(reg);        printf( "Registry %s opened OK.\n", argv[1] ? argv[1] : "<default>" );                    // Recurse over all 3 branches.        display( reg, nsIRegistry::Common, "nsRegistry::Common" );        display( reg, nsIRegistry::Users, "nsRegistry::Users" );        display( reg, nsIRegistry::Common, "nsRegistry::CurrentUser" );    }    if (argc == 1) {        // Called with no arguments. Print both the default registry and         // the components registry. We already printed the default regsitry.        // So just do the component registry.        rv = reg->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);        if ( rv == NS_OK ) {            NS_ADDREF(reg);            printf( "Registry %s opened OK.\n", argv[1] ? argv[1] : "<Application Component Registry>" );                        // Recurse over all 3 branches.            display( reg, nsIRegistry::Common, "nsRegistry::Common" );            display( reg, nsIRegistry::Users, "nsRegistry::Users" );            display( reg, nsIRegistry::Common, "nsRegistry::CurrentUser" );        }    }    NS_RELEASE(reg);    return rv;}