Visit Mozilla.org

nsIUUIDGenerator

From MDC

nsIUUIDGenerator can be used to generate an ID that can be considered globally unique, often referred to as a UUID or GUID. This interface is only available in Firefox 2 or newer.

nsIUUIDGenerator is defined in xpcom/base/nsIUUIDGenerator.idl. It is scriptable and unfrozen (hasn't changed since Mozilla 1.8.1).

If you just need to generate a GUID, see Generating GUIDs.

Contents

[edit] Methods

[edit] generateUUID

nsIDPtr generateUUID();

generateUUID() generates and returns an object containing a unique ID.

[edit] Return Values

This method returns an object of type Components.ID containing a unique ID.

[edit] Exceptions

NS_ERROR_FAILURE

Indicates that the system could not generate a UUID.

[edit] generateUUIDInPlace

[noscript] void generateUUIDInPlace(in nsNonConstIDPtr id);

generateUUIDInPlace() allows C++ code to generate a UUID and store the result in a stack allocated variable instead of allocating space for the structure on the heap.

[edit] Parameters

id

A pointer to an nsID structure to hold the generated UUID.

[edit] Exceptions

NS_ERROR_FAILURE

Indicates that the system could not generate a UUID.

[edit] Example Code

[edit] Generating a UUID

var uuidGenerator = 
  Components.classes["@mozilla.org/uuid-generator;1"]
            .getService(Components.interfaces.nsIUUIDGenerator);
var uuid = uuidGenerator.generateUUID();
var uuidString = uuid.toString();