Creating XPCOM XULRunner 2.0 or later

Follow these questions:

What lib in gecko 1.9.3 SDK do I link against using moz_xmalloc ()?

nsIGenericFactory.h is missing from the above version of xulrunner-2.0.en-US.win32.sdk

I can successfully create XPCOM with XULRunner 1.9.2.

When I try to upgrade to the next versions of XULRunner (> 1.9), I have a lot of difficulties. I get communication errors as below.

xpcomglue_s.lib(GenericFactory.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc xpcomglue_s.lib(nsCRTGlue.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc xpcomglue_s.lib(nsTArray.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc xpcomglue_s.lib(nsComponentManagerUtils.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc xpcomglue_s.lib(GenericModule.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc xpcomglue_s.lib(nsISupportsImpl.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc 

I am not getting clear migration steps to support the current FireFox.

I tried the suggestions mentioned in the links. I could not allow it. Please help me solve this problem.

+4
source share
2 answers

I was hoping someone would provide a complete list of what needs to be changed in order to make him work on a later gecko, but since no one did, I will try to do it myself using this sample I just found.

xpidl.exe

I do not know if this has changed or not, so it may not be necessary. There is no xpidl.exe in Gecko 11. The solution for this is from Philip Chee

It has been replaced with a Python script. You can continue to use the XPIDL from the Gecko 7.0 SDK or compile it from the source or use the Python script.

Gecko 7.0 can be downloaded from ftp HERE . It really has xpidl.exe. Usage is the same as in the example.

Component module implementation

This seems to have changed a lot. The link in MDN is another link (which goes back to the sample shown above, but explains the material).

Note that nsIGenericFactory.h has been deleted. Links to nsIGenericFactory.h should be replaced by mozilla / ModuleUtils.h

In the example project, #include "nsIClassInfoImpl.h" added.

Now the biggest step is to change the NS_IMPL_NSGETMODULE (which is also deleted), and the components declaration, which is used by this for the whole collection of things found in the sample module . You could use the declaration of components for reference, I did a little help.

The only thing you do not need in this example is declaring and using kSampleCategories . Just replace it with NULL . At least what Benjamin Smedberg said .

The constant kNS_SAMPLE_CID should be replaced with kYOUR_CID_CONSTANT . Just add k to you CID constant name.

Last line:

 NS_IMPL_MOZILLA192_NSGETMODULE(&kSampleModule) 

Only required for compatibility with Gecko 1.9. Since firefox 3.5 uses this, I think I will leave it.

Component Implementation (CompImpl.cpp)

Link from sample .

  • Add the line NS_IMPL_CLASSINFO... (in sample line 80)
  • Replace NS_IMPL_ISUPPORTS1 with NS_IMPL_ISUPPORTS1_CI

There are tons of good examples in this example of how to use I / O values. If you want to use char *, you also need to use nsMemory. I think this is not necessary for nsStrings.

XPCOM Glue without mozalloc

Here we are again going to associate the errors with __imp__moz_xmalloc . This small, very difficult to find article helped get rid of them:

Starting with XULRunner 2.0, the freeze-sensitive adhesive (xpcomglue_s.lib on Windows, libxpcomglue_s.a on Linux and Mac) is dependent on the new functions of error-free memory (mozalloc). Since these procedures did not exist before XULRunner 2.0, XPCOM components that are associated with frozen bond-dependent adhesives will not be compatible with XULRunner applications prior to 2.0.

The solution is to refer to xpcomglue_s_nomozalloc instead (xpcomglue_s_nomozalloc.lib for Windows, libxpcomglue_s_nomozalloc.a on Linux and Mac). This library is new in XULRunner 2.0, and it is identical to xpcomglue_s, except that it is compiled without mozalloc. Just change all references to "xpcomglue_s" in your compiler and linker flags to "xpcomglue_s_nomozalloc". The resulting components of XPCOM will no longer be dependent on mozalloc, and thus will be compatible with XULRunner applications up to 2.0.

A comment. You may also need to create your component using the MOZ_NO_MOZALLOC flag (-DMOZ_NO_MOZALLOC)

And finally, there is no mistake

+4
source

This seems to be a common problem. I see you already found this thread and tried the standard tip, but for others:

define 'XPCOM_GLUE' in the C ++ preprocessor definition property. This will fix the binding error.

Since you already have this place, the next fix you should try is actually further down the page:

Try defining MOZ_NO_MOZALLOC when compiling your extension, you will then get a DLL that uses your CRT allocators. (Remember to use NS_ * allocators for XPCOM-compatible memory .

You can do this by adding #define MOZ_NO_MOZALLOC to the contents of your extension, in configure when creating XULRunner, or in the contents of individual files such as mozilla-config.h .

Despite the fact that you probably already tried to do this, at least it should solve the problem with the linker.

Edit: For the benefit of the bonus provider, here's a tip to solve the __cdecl NS_NewGenericModule2 .

+1
source

Source: https://habr.com/ru/post/1389239/


All Articles