fileName.ToCString(szFile, sizeof(szFile) - 1);
PL_strncpyz(szFile, fileName.get(), sizeof(szFile) - 1);
void SaveWebPage(nsIWebBrowser *aWebBrowser){    // Use the browser window title as the initial file name    nsCOMPtr<nsIBaseWindow> webBrowserAsWin = do_QueryInterface(aWebBrowser);	nsXPIDLString windowTitle;	webBrowserAsWin->GetTitle(getter_Copies(windowTitle));    nsCString fileName; fileName.AssignWithConversion(windowTitle);	// Sanitize the title of all illegal characters    fileName.CompressWhitespace();     // Remove whitespace from the ends    fileName.StripChars("\\*|:\"><?"); // Strip illegal characters    fileName.ReplaceChar('.', L'_');   // Dots become underscores    fileName.ReplaceChar('/', L'-');   // Forward slashes become hyphens    // Copy filename to a character buffer	char szFile[_MAX_PATH];    memset(szFile, 0, sizeof(szFile));    fileName.ToCString(szFile, sizeof(szFile) - 1);    // Initialize the file save as information structure    OPENFILENAME saveFileNameInfo;    memset(&saveFileNameInfo, 0, sizeof(saveFileNameInfo));	saveFileNameInfo.lStructSize = sizeof(saveFileNameInfo);	saveFileNameInfo.hwndOwner = NULL;	saveFileNameInfo.hInstance = NULL;	saveFileNameInfo.lpstrFilter =        "Web Page, HTML Only (*.htm;*.html)\0*.htm;*.html\0"        "Web Page, Complete (*.htm;*.html)\0*.htm;*.html\0"        "Text File (*.txt)\0*.txt\0"; 	saveFileNameInfo.lpstrCustomFilter = NULL; 	saveFileNameInfo.nMaxCustFilter = NULL; 	saveFileNameInfo.nFilterIndex = 1; 	saveFileNameInfo.lpstrFile = szFile; 	saveFileNameInfo.nMaxFile = sizeof(szFile); 	saveFileNameInfo.lpstrFileTitle = NULL;	saveFileNameInfo.nMaxFileTitle = 0; 	saveFileNameInfo.lpstrInitialDir = NULL; 	saveFileNameInfo.lpstrTitle = NULL; 	saveFileNameInfo.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; 	saveFileNameInfo.nFileOffset = NULL; 	saveFileNameInfo.nFileExtension = NULL; 	saveFileNameInfo.lpstrDefExt = "htm"; 	saveFileNameInfo.lCustData = NULL; 	saveFileNameInfo.lpfnHook = NULL; 	saveFileNameInfo.lpTemplateName = NULL; 	if (GetSaveFileName(&saveFileNameInfo))	{        // Does the user want to save the complete document including        // all frames, images, scripts, stylesheets etc. ?        char *pszDataPath = NULL;        if (saveFileNameInfo.nFilterIndex == 2) // 2nd choice means save everything        {            static char szDataFile[_MAX_PATH];            char szDataPath[_MAX_PATH];            char drive[_MAX_DRIVE];            char dir[_MAX_DIR];            char fname[_MAX_FNAME];            char ext[_MAX_EXT];            _splitpath(szFile, drive, dir, fname, ext);            sprintf(szDataFile, "%s_files", fname);            _makepath(szDataPath, drive, dir, szDataFile, "");            pszDataPath = szDataPath;       }        // Save away        nsCOMPtr<nsIWebBrowserPersist> persist(do_QueryInterface(aWebBrowser));        nsCOMPtr<nsILocalFile> file;        NS_NewLocalFile(szFile, TRUE, getter_AddRefs(file));        nsCOMPtr<nsILocalFile> dataPath;        if (pszDataPath)        {            NS_NewLocalFile(pszDataPath, TRUE, getter_AddRefs(dataPath));        }        persist->SaveDocument(nsnull, file, dataPath);	}}