HGLOBAL createGlobalData(const KURL& url, const String& title)
{
    String mutableURL(url.string());
    String mutableTitle(title);
    SIZE_T size = mutableURL.length() + mutableTitle.length() + 2;  // +1 for "\n" and +1 for null terminator
    HGLOBAL cbData = ::GlobalAlloc(GPTR, size * sizeof(UChar));

    if (cbData) {
        PWSTR buffer = (PWSTR)::GlobalLock(cbData);
        swprintf_s(buffer, size, L"%s\n%s", mutableURL.charactersWithNullTermination(), mutableTitle.charactersWithNullTermination());
        ::GlobalUnlock(cbData);
    }
    return cbData;
}
nsresult
nsXULContentUtils::MakeElementURI(nsIDocument* aDocument,
                                  const nsAString& aElementID,
                                  nsCString& aURI)
{
    // Convert an element's ID to a URI that can be used to refer to
    // the element in the XUL graph.

    nsIURI *docURL = aDocument->GetDocumentURI();
    NS_ENSURE_TRUE(docURL, NS_ERROR_UNEXPECTED);

    nsCOMPtr<nsIURI> docURIClone;
    nsresult rv = docURL->Clone(getter_AddRefs(docURIClone));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIURL> mutableURL(do_QueryInterface(docURIClone));
    NS_ENSURE_TRUE(mutableURL, NS_ERROR_NOT_AVAILABLE);

    rv = mutableURL->SetRef(NS_ConvertUTF16toUTF8(aElementID));
    NS_ENSURE_SUCCESS(rv, rv);

    return mutableURL->GetSpec(aURI);
}