Hi all ,
I have written a simple program in c++ to access the XPCOM component in mozilla build. I got the run time error when i executed following program:
Line which failed to execute successfully:
rv = NS_InitXPCOM2(getter_AddRefs(servMan),nsnull, nsnull);
Error:
ERROR: XPCOM intialization error [c1f30001].
My code:
#include "C:\gecko-sdk\xpcom\include\nsMemory.h"
#else
#include "nsXPIDLString.h"
#endif
#else
#include "nsXPIDLString.h"
#endif
#define NS_HELLO_CONTRACTID "@mozilla.org/websample;1"
int main(void)
{
nsresult rv;
// Initialize XPCOM
nsCOMPtr<nsIServiceManager> servMan;
rv = NS_InitXPCOM2(getter_AddRefs(servMan),nsnull, nsnull);//
{
nsresult rv;
// Initialize XPCOM
nsCOMPtr<nsIServiceManager> servMan;
rv = NS_InitXPCOM2(getter_AddRefs(servMan),nsnull, nsnull);//
if (NS_FAILED(rv))
{
printf("ERROR: XPCOM intialization error [%x].\n", rv);
return -1;
}
{
printf("ERROR: XPCOM intialization error [%x].\n", rv);
return -1;
}
// register all components in our default component directory
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
registrar->AutoRegister(nsnull);
nsCOMPtr<nsIComponentManager> manager = do_QueryInterface(registrar);
nsCOMPtr<nsIComponentManager> manager = do_QueryInterface(registrar);
NS_ASSERTION(registrar, "Null nsIComponentManager");
// Create an instance of our component
nsCOMPtr<nsIHello> myhello;
rv = manager->CreateInstanceByContractID(NS_HELLO_CONTRACTID,
nsnull,
NS_GET_IID(nsIHello),
getter_AddRefs(myhello));
if (NS_FAILED(rv))
{
printf("ERROR: Cannot create instance of component " NS_HELLO_CONTRACTID " [%x].\n"
"Debugging hint:\n"
"\tsetenv NSPR_LOG_MODULES nsComponentManager:5\n"
"\tsetenv NSPR_LOG_FILE xpcom.log\n"
"\t./nsTestHello\n"
"\t<check the contents for xpcom.log for possible cause of error>.\n",
rv);
return -2;
}
nsnull,
NS_GET_IID(nsIHello),
getter_AddRefs(myhello));
if (NS_FAILED(rv))
{
printf("ERROR: Cannot create instance of component " NS_HELLO_CONTRACTID " [%x].\n"
"Debugging hint:\n"
"\tsetenv NSPR_LOG_MODULES nsComponentManager:5\n"
"\tsetenv NSPR_LOG_FILE xpcom.log\n"
"\t./nsTestHello\n"
"\t<check the contents for xpcom.log for possible cause of error>.\n",
rv);
return -2;
}
// Call methods on our Hello to test it out.
rv = myhello->Write();
if (NS_FAILED(rv))
{
printf("ERROR: Calling nsIHello::Write() [%x]\n", rv);
return -3;
}
/*
const char *testValue = "XPCOM ";
rv = myhello->Write();
if (NS_FAILED(rv))
{
printf("ERROR: Calling nsIHello::Write() [%x]\n", rv);
return -3;
}
/*
const char *testValue = "XPCOM ";
rv = myHello->change(testValue);
if (NS_FAILED(rv))
{
printf("ERROR: Calling nsIHello::SetValue() [%x]\n", rv);
return -3;
}
printf("Set value to: %s\n", yourname);
{
printf("ERROR: Calling nsIHello::SetValue() [%x]\n", rv);
return -3;
}
printf("Set value to: %s\n", yourname);
// All nsCOMPtr's must be deleted prior to calling shutdown XPCOM
// as we should not hold references passed XPCOM Shutdown.
// as we should not hold references passed XPCOM Shutdown.
printf("\nkkk");
nsCOMPtr<nsIComponentManager> compMgr;
rv = NS_GetComponentManager(getter_AddRefs(compMgr));
if (NS_FAILED(rv)) return rv;
nsIHello* stringSupports;
compMgr->CreateInstanceByContractID(NS_HELLO_CONTRACTID, nsnull,NS_GET_IID(nsIHello),(void**)&stringSupports);
printf("\nrrrrkkk");
stringSupports->Write();
rv = NS_GetComponentManager(getter_AddRefs(compMgr));
if (NS_FAILED(rv)) return rv;
nsIHello* stringSupports;
compMgr->CreateInstanceByContractID(NS_HELLO_CONTRACTID, nsnull,NS_GET_IID(nsIHello),(void**)&stringSupports);
printf("\nrrrrkkk");
stringSupports->Write();
servMan = 0;
registrar = 0;
manager = 0;
myhello = 0;
*/
// Shutdown XPCOM
NS_ShutdownXPCOM(nsnull);
return 0;
}
registrar = 0;
manager = 0;
myhello = 0;
*/
// Shutdown XPCOM
NS_ShutdownXPCOM(nsnull);
return 0;
}
Can any body help me out
Nikhil Kadu
Yahoo! India Matrimony: Find your life partner online.
