Hello All,

 I am new to embedding mozilla in application.

 I was using IE COM Component to extract web page and do some parsing on the 
content. Now I want to move to
Mozilla since it is supported on multiple platform. I am doing so in Unix 
environment.

  I am trying to web browser component using folllowing code snippet.

  GetServiceByContractID is returning error.

Factory not registered..
Failed to get web browser: 80040154
Total bytes :0
Failed to get web browser: Z 0�

Can someone please help me out here?

NOTE: I tried doing without calling NS_InitXPCOM2 too...

Thanx,
-- baliga


#include <string.h> #include <stdio.h> #include <nsIServiceManager.h> #include <nsCOMPtr.h> #include <nsXPCOM.h> #include <nsError.h> #include <iostream> #include <nsIWebBrowser.h> #include <nspr/prerror.h> #include <nsILocalFile.h> #include <string/nsString.h>

int
main()
{

  nsCOMPtr<nsILocalFile> nsFile;
  NS_NewLocalFile(NS_LITERAL_STRING("/usr/X11R6/lib/firefox/bin"), false, 
getter_AddRefs(nsFile));

  if (NS_InitXPCOM2(nsnull, nsFile, nsnull) != NS_OK) {
    cerr << "Failed to initialize xpcom" << endl;
    exit (1);
  }

  nsCOMPtr<nsIServiceManager> servMan;
  nsresult r = NS_GetServiceManager(getter_AddRefs(servMan));

  if (NS_FAILED(r)) {
    cerr << "Failed to get service manager.." << endl;
  }


nsCOMPtr<nsIWebBrowser> webBrowser;
r = servMan->GetServiceByContractID("@mozilla.org/embedding/nsWebBrowser;1", NS_GET_IID(nsIWebBrowser), getter_AddRefs(webBrowser));


  if (NS_FAILED(r)) {

    if (r == NS_ERROR_FACTORY_NOT_REGISTERED) {
      cerr << "Factory not registered.." << endl;
    }

    char errStr[1024];
    printf("Total bytes :%d\n", PR_GetErrorText(errStr));
    printf("Failed to get web browser: %s\n", errStr);
  }
}
_______________________________________________
mozilla-embedding mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-embedding

Reply via email to