简体   繁体   English

使用C ++ Builder中的7zip Delphi包装器

[英]Using 7zip Delphi wrapper from C++ Builder

I'm trying to utilize "7za.dll" together with this Delphi wrapper - http://www.progdigy.com/?page_id=13 我正在尝试将“ 7za.dll”与此Delphi包装器一起使用-http://www.progdigy.com/?page_id =13

Having difficulties translating this code to C++ and understanding the wrapper itself: 在将此代码转换为C ++和理解包装器本身方面遇到困难:

procedure TMainForm.ExtractAllClick(Sender: TObject);
  var Arch: I7zOutArchive;
begin
  Arch := CreateOutArchive(CLSID_CFormat7z);
  // add a file
  Arch.AddFile('c:\test.bin', 'folder\test.bin');
  // add files using willcards and recursive search
  Arch.AddFiles('c:\test', 'folder', '*.pas;*.dfm', true);
  // add a stream
  Arch.AddStream(aStream, soReference, faArchive, CurrentFileTime, CurrentFileTime, 'folder\test.bin', false, false);
  // compression level
  SetCompressionLevel(Arch, 5);
  // compression method if <> LZMA
  SevenZipSetCompressionMethod(Arch, m7BZip2);
  // add a progress bar ...
  Arch.SetProgressCallback(...);
  // set a password if necessary
  Arch.SetPassword('password');
  // Save to file
  Arch.SaveToFile('c:\test.zip');
  // or a stream
  Arch.SaveToStream(aStream);
end;

I've made additional wrapper of wrapper Delphi unit which when included in C++ code wraps above and it works. 我已经制作了包装Delphi单元的附加包装器,当包含在C ++代码中时,该包装器就可以正常工作了。 Now I'd like to use it a step further - call the above in C++ code directly. 现在,我想进一步使用它-直接在C ++代码中调用上面的代码。

How do I initialize, construct and release this I7zOutArchive interface properly in C++? 如何在C ++中正确初始化,构造和释放此I7zOutArchive接口?

Is there a need to destroy (free memory) in above code or is it automatic when it goes out of scope (I usually use boost::scoped_ptr to do the job, is something like that required here)? 是否需要销毁上述代码中的(空闲内存),还是在超出范围时自动删除(我通常使用boost::scoped_ptr来完成这项工作,此处需要类似的东西)吗?

You do need to destroy the thing returned by CreateOutArchive , but scoped_ptr would be inappropriate. 您确实需要销毁CreateOutArchive返回的CreateOutArchive ,但是scoped_ptr不合适。 Instead, use the built-in System::DelphiInterface class: 而是使用内置的System::DelphiInterface类:

System::DelphiInterface<I7zOutArchive> Arch = CreateOutArchive(CLSID_CFormat7z);

Then, call methods on that object the same as you would any other COM interface. 然后,对该对象上的调用方法与其他任何COM接口相同。 (Replace Delphi's . operator with -> , and you're most of the way there.) The object will get destroyed when the reference count reaches zero, which generally occurs when Arch goes out of scope. (用->替换Delphi的.运算符,您就可以使用它的大部分方式。)当引用计数达到零时,对象将被销毁,通常在Arch超出范围时发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM