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:

bool XPCOMTest::createXPCOMObject(const char* contractId, nsISupports**
ppXPCOM) {
        nsresult rv;
        nsCOMPtr<nsISupports> pXPCOM = do_CreateInstance(contractId, &rv);
        if (rv != NS_OK) {
                printf("The return code from do_CreateInstance is %d\n", rv);
        }
        *ppXPCOM = pXPCOM.get();
        NS_IF_ADDREF(*ppXPCOM);
        return true;
}

int main(int argc, char *argv[]) {
        if (argc == 1) {
                printf("Usage: XPCOMTest <contract_id> [<contract_id]*\n");
                return 0;
        }
        XPCOMTest testObj;
        for (int i = 1; i < argc; i++) {
                nsCOMPtr<nsISupports> pXPCOM = NULL;
                printf("Attempting create object: %s\n", argv[i]);
                testObj.createXPCOMObject(argv[i], getter_AddRefs(pXPCOM));
                if (pXPCOM != NULL) {
                        printf("Succeeded in creating component: %s\n", 
argv[i]);
                } else {
                        printf("Failed to create component: %s\n", argv[i]);
                }
        }
        return 1;
}

My platform is Linux, FC3, I am linking against the following
libraries:
-lxpcomglue -lnspr4 -lplds4
I have set the LD_LIBRARY_PATH to the "components" directory of my
Mozilla installation.

Thanks for any help.

-Sandip

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

Reply via email to