0

I created a FireFox addon a while a go, and noticed it stopped working on FireFox 3.6 Apparently, NSGetModule is being replaced with an NSModule structure, so I have to adapt. I'm coding my product with Delphi, so I have to port the new code to Object Pascal.

If I look over this code: http://mxr.mozilla.org/mozilla-central/source/xpcom/components/Module.h

I notice that the "cid" property of the ContractIDEntry struct, is defined as nsID const *

Does this mean that there's a pointer to a nsID variable in the struct, or that the nsID value is itself part of the struct?

Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67

1 Answers1

3

The full declaration is this:

struct ContractIDEntry
{
  const char* contractid;
  nsID const * cid;
};

Just as the declaration of contractid means that the struct contains a pointer to a char and not that the char is part of the struct, the declaration of cid means the struct contains a pointer to an nsID. The struct does not contain an nsID, merely a pointer to one.

Technically, it's a pointer that is not allowed to be used to modify the pointed-to value, but Delphi doesn't have that concept, so declare it as just an ordinary pointer.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • Thank you I'll check if I get this to work. Odd thing is, the folks over at Mozilla changed NSGetModule into NSModule 'to not have to load the module to get it to register itself', but I'll have to get the initialization code called so I can initialize the record, don't I? IT works that way on my Apache module... – Stijn Sanders Nov 01 '10 at 16:38
  • Mozilla's change is a regression. It requires that compilers support exporting *data* instead of just exporting *functions*. Previously, you would export a function, and the host program would call it to get plug-in information. Now, you have to export a variable; the host can load your module without executing initialization functions, look up the address of the exported variable, and read the *static* data there. Delphi cannot export variables, so you can no longer write add-ons in Delphi (or any of several other tools, either). I invite you to submit a bug report to Mozilla. – Rob Kennedy Nov 01 '10 at 16:51
  • Turns out the DLL's init code is called, so I can init an exported record from Delphi (much like Apache)! One more question, though, is `const CIDEntry* mCIDs` (and following) an array of pointers, or an array of CIDEntry's, and if the latter, is `{NULL}` a CIDEntry with all bytes/bits set to 0? – Stijn Sanders Nov 04 '10 at 23:04
  • Anything that ends with `*` is a pointer. It might be a pointer to the first element of an array, or it might be the point to just one thing. I expect Mozilla documentation tells you which. A struct initialized with `{NULL}` has its first element set to a null pointer, and the rest of its elements get their "default" values, which will usually be `0`, `false`, or `NULL`. An array initialized with `{NULL}` has its first element set to the null pointer, and the remaining elements, if there are any, get their default values, which would also be null pointers. – Rob Kennedy Nov 05 '10 at 15:27