RL Clippard wrote:
> Does "nsResult = NS_InitXPCOM2(nsnull, nsnull, nsnull);" have to supply the
> directory to the Netscape components or does it 'know'?
On Windows you have to tell it. Linux knows. I can't recall the
details of exactly why, but this was certainly the case 18 months ago.
I guess it is still the same.
> Also my version of
> Netscape (6.2) xpcom.dll does not allow NS_InitXPCOM2() - I assumed this is
> just a minor issue so I am using the xpcom.dll that came with mozilla.9.9.
>
> //-nsLocalFile
> nsCOMPtr<nsILocalFile> componentPath=0;
> componentPath= do_CreateInstance(NS_LOCAL_FILE_CONTRACTID,&nsResult);
>
> const char *path = "C:\\Program Files\\Netscape\\Netscape 6";
> // Where Netscape is installed
> nsResult = componentPath->InitWithPath(path);
>
> PRBool isDirectory;
> nsResult = componentPath->IsDirectory(&isDirectory);
> printf("%s ---<%s>--- a directory\n",path,isDirectory?"IS":"IS NOT");
> // This works (is indeed a directory)
>
> //-initXPCOM
> nsIServiceManager *serviceManager=0;
> nsResult = NS_InitXPCOM2(&serviceManager, componentPath, nsnull);
> // This fails! ---> 0x80004005
This is from the PyXPCOM code (mozilla/extensions/python/xpcom)
...
nsCOMPtr<nsIThread> thread_check;
// xpcom appears to assert if already initialized
// Is there an official way to determine this?
if
(NS_FAILED(nsIThread::GetMainThread(getter_AddRefs(thread_check)))) {
// not already initialized.
// We need to locate the Mozilla bin directory.
#ifdef XP_WIN
// On Windows this by using "xpcom.dll"
char landmark[MAX_PATH+1];
HMODULE hmod = GetModuleHandle("xpcom.dll");
if (hmod==NULL) {
PyErr_SetString(PyExc_RuntimeError, "We dont appear to be
linked against xpcom.dll!?!?");
return PR_FALSE;
}
GetModuleFileName(hmod, landmark,
sizeof(landmark)/sizeof(landmark[0]));
char *end = landmark + (strlen(landmark)-1);
while (end > landmark && *end != '\\')
end--;
if (end > landmark) *end = '\0';
nsCOMPtr<nsILocalFile> ns_bin_dir;
NS_NewLocalFile(landmark, PR_FALSE, getter_AddRefs(ns_bin_dir));
nsresult rv = NS_InitXPCOM2(nsnull, ns_bin_dir, nsnull);
#else
// Elsewhere, Mozilla can find it itself (we hope!)
nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
#endif // XP_WIN
if (NS_FAILED(rv)) {
...
Mark.