Thanks for the extremely detailed description.
Seems GRE_Startup() is the right function to be called at the startup, and it does work with my own build of mozilla 1.4. But once I copied my app into the installed mozilla 1.4 (downloaded from http://ftp.mozilla.org/pub/mozilla/releases/mozilla1.4/mozilla-win32-1.4-installer.exe) directory (C:\Program Files\mozilla.org\Mozilla), neither
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)) nor
nsCOMPtr<nsIProfile> profileService(do_GetService(NS_PROFILE_CONTRACTID)) return the correct value for me.
What's wrong with my code?
Thanks Kyle
Kevin Ollivier wrote:
Hi Kyle,
When you say that you have failed, do you mean in the linking stage, or on application startup? In either case, posting whatever error messages you received would be helpful.
Still, I think the switch to XPCOMGlue is indeed a bit confusing, so let me try and explain these things as I understand them. (I didn't write this code, but I've been through it quite a few times. =)
If you are linking against XPCOMGlue, you now need to directly link against the NSPR libraries (nspr4, plc4, plds4) and directly against either embed_string_s or string_s and string_obsolete_s libraries. Unless you are sure that you are using only the string classes defined in embed_string_s, the safe way is to link against string_s and string_obsolete_s.
NS_InitEmbedding cannot currently be used with XPCOMGlue because it statically links with XPCOM. I think there is work towards making NS_InitEmbedding work with XPCOMGlue, however, so this may change in the future.
GREStartup tries to automatically discover the path to the GRE (using the registry on Windows), start XPCOM, and initialize embedding using NS_InitXPCOM2 (called with default options). NS_InitXPCOM2 is similar to NS_InitEmbedding except that it uses the XPCOMGlue library. The downside is that GREStartup doesn't let you specify any options. (i.e. it will assume your components dir is underneath the cwd, which isn't always the case) Of course, if you use GREStartup you need to use GREShutdown to shut down embedding.
Please see here for the routine GREStartup uses to find where the GRE is located, as it may contain some clues as to why GREStartup is failing for you:
http://lxr.mozilla.org/seamonkey/source/xpcom/glue/standalone/ nsGREDirServiceProvider.cpp#292
XPCOMGlueStartup just starts up XPCOMGlue, but does not call NS_InitXPCOM2 to start embedding. If you want to emulate NS_InitEmbedding behavior, as I understand it, you need to call XPCOMGlueStartup() and then call NS_InitXPCOM2 afterwards. To shut down, you call NS_ShutdownXPCOM first and then XPCOMGlueShutdown.
BTW, NS_InitXPCOM2 is defined here:
http://lxr.mozilla.org/seamonkey/source/xpcom/glue/standalone/ nsXPCOMGlue.cpp#154
If I've misstated anything, I apologize in advance and hope someone will step in and correct me. =)
HTH,
Kevin
On Sunday, August 17, 2003, at 11:35 PM, Kyle Yuan wrote:
Hi all,
Before I linked my gecko-embedded app to xpcomglue library, the only thing I need to do for initializing xpcom is call NS_InitEmbedding. But if I use the xpcomglue library (instead of linking directly to XPCOM_LIBS), things become complicated and confused - there are 3 initialization functions: NS_InitEmbedding, GRE_Startup and XPCOMGlueStartup. I don't know which of them should be called and by what order. I've made some tries, but all failed.
I also noticed that both mfcembed & winembed in thunk are not gre-compliance yet. Where can I find any examples of embedding apps using xpcomglue?
Thanks
Kyle
