Thanks for your response. I have been using XPCOM for the past month or
so,  created a C++ XPCOM component that I am using in javascript within
a XULRunner application. Have not tried using an XPCOM component in a
stand-alone manner from a C++ app before.

I read through the link you sent me and added the following functions
to initialize and un-initialize XPCOM.

bool XPCOMTest::initXPCOM() {
        nsresult rv;
        nsCOMPtr<nsILocalFile> file;
//      rv =
NS_NewLocalFile(NS_LITERAL_STRING("<path_to_firefox>/components"),
PR_FALSE,
//                           getter_AddRefs(file));
//      if (NS_FAILED(rv)) {
//              return false;
//      }
        rv = NS_InitXPCOM2(getter_AddRefs(_serviceManager), nsnull, nsnull);
        if (NS_FAILED(rv)) {
                printf("Failed to initialized XPCOM2\n");
                return false;
        }
        return true;
}

void XPCOMTest::shutDownXPCOM() {
        NS_ShutdownXPCOM(_serviceManager);
}

However the NS_InitXPCOM2 method is always failing. I have tried
passing a nsILocalFile as in the commented out code above the
NS_InitXPCOM2 call, that has also failed.

I am attempting the Standalone Glue strategy, linking to the following
libraries:
-lxpcomglue -lplds4
I was getting link errors without the second library. The original list
of library linkage came from the XPCOM component I created.

Thanks for your help.

-Sandip

Benjamin Smedberg wrote:
> [EMAIL PROTECTED] wrote:
> > I am attempting to instantiate an XPCOM component in simple C++
> > application. The goal is to write unit tests for my XPCOM component.
> > The XPCOM instantiation always fails. Here is my instantiation code:
>
> > int main(int argc, char *argv[]) {
> >     if (argc == 1) {
> >             printf("Usage: XPCOMTest <contract_id> [<contract_id]*\n");
> >             return 0;
> >     }
> >     XPCOMTest testObj;
>
> You have never initialized XPCOM! You cannot create XPCOM objects (or call
> almost any XPCOM functions, for that matter) until you have called
> NS_InitXPCOM2 (or NS_InitXPCOM3).
>
> > My platform is Linux, FC3, I am linking against the following
> > libraries:
> > -lxpcomglue -lnspr4 -lplds4
>
> Which linking strategy are you trying to use? This looks like a mishmash of
> the "standalone" strategy with -lxpcomglue and the "dependent" strategy.
>
> http://developer.mozilla.org/en/docs/XPCOM_Glue
>
> > I have set the LD_LIBRARY_PATH to the "components" directory of my
> > Mozilla installation.
>
> This should not be necessary. It probably *will* be necessary to launch your
> application with the run-mozilla.sh script to set up LD_LIBRARY_PATH to
> point to the application directory and possibly set MOZILLA_FIVE_HOME.
> 
> --BDS

_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to