delphi - 创造 *。 Mht 文件(网络存档)

标签 delphi blocking mhtml imessage

使用以下函数表示从本地 html 文件生成 Web 存档

function TLessonConstructor2.CreateMHT( const FileName : string):boolean ;
 var
  oMSG:IMessage;
  oConfig: IConfiguration;
  sFileName: string;
  Stream: _Stream;
begin
  //CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
  //CoInitialize(nil);
  try
    Result  := false;
    sFileName := ChangeFileExt(FileName, '.mht');
    DeleteFile(PAnsiChar(sFileName));
    try
    oConfig := CoConfiguration.Create();
    oMSG    := CoMessage.Create();
    oMSG.Configuration := oConfig;
    oMSG.CreateMHTMLBody(FileName,CdoSuppressNone,'','');
    Stream:=oMSG.GetStream;
    Stream.SaveToFile(sFileName,adSaveCreateOverWrite);
    Stream.Cancel;
    Stream.Close;
    Result := True;
    except
      on E: Exception do
      begin
       Result  := false;
       MessageDlg(E.Message, mtError, [mbOK], 0);
      end;
    end;
  finally
  //  CoUnInitialize;
    Stream:=nil;
    oConfig:=nil;
    oMSG:=nil;
  end;
end;

文件名 - html 的完整路径。

执行oMSG.CreateMHTMLBody(FileName, CdoSuppressNone,'','')后;只要基本过程完成,该文件就会被锁定。但是,处理后应删除该文件。

知道问题出在哪里吗?

最佳答案

创建 HTML 正文需要 URL,因此对于本地文件,请确保前面带有 file:///

CreateMHTMLBody(const URL: WideString; Flags: CdoMHTMLFlags; 
                          const UserName: WideString; const Password: WideString); safecall;

关于delphi - 创造 *。 Mht 文件(网络存档),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12690331/

相关文章:

delphi - 如何获取 Delphi 编译包(.dcp 文件)中的单元列表

delphi - 表格出现在 'Application.CreateForm' 步骤之后

c - 从c中连接的udp套接字中读取返回

asp.net - 如何在DB中组织ASP.NET请求锁定或行锁定

javascript - 禁止使用 Meteor 帐户的系统?

c# - WPF WebBrowser 和特殊字符,如德语 "umlaute"

performance - CreateProcess 的快速替代方案

delphi - 透明位图作为资源?

javascript - 链接阅读有关新闻通讯 HTML 的更多信息