简体   繁体   English

从C ++项目显式链接DLL-(7zip,7z.dll)

[英]Explicit Linking DLL from C++ Project - (7zip, 7z.dll)

I am trying to use 7zip from within my application code. 我正在尝试从我的应用程序代码中使用7zip。 On 7zip's website, they say I can use 7z.dll. 在7zip的网站上,他们说我可以使用7z.dll。 So, I tried to reference it from C#, but that didn't work. 因此,我尝试从C#引用它,但这没有用。 So, I decided to write a C++ library that references 7z.dll, and then I can reference that library from C#. 因此,我决定编写一个引用7z.dll的C ++库,然后可以从C#中引用该库。

I was able to load the library (I think) in my C++ library, and I am able to reference that library from C# and successfully call a method. 我能够在我的C ++库中加载该库(我认为),并且能够从C#引用该库并成功调用方法。

However, I don't know how to figure out the method names inside the 7z.dll library so that I can call them. 但是,我不知道如何找出7z.dll库中的方法名称,以便我可以调用它们。

Please help 请帮忙

Hmm, Hans Passant pointed out SevenZipSharp which makes my answer rather useless ;-) I'll leave it for purely educational purposes. 嗯,汉斯·帕桑(Hans Passant)指出SevenZipSharp,这使我的回答变得毫无用处;-)我将其纯粹用于教育目的。 No need to write your own COM interop wrappers if somebody else has already done it for you... 如果其他人已经为您完成了操作,则无需编写自己的COM互操作包装器。


I had a look at their C++ example (under CPP/7zip/UI/Client7z). 我看了看他们的C ++示例(在CPP / 7zip / UI / Client7z下)。 Everything is done using COM interfaces and various types of callbacks. 一切都使用COM接口和各种类型的回调完成。

While C# has excellent COM interop support, it would require redeclaring the relevant COM interfaces in C#, or perhaps using late-bound dynamic magic instead. 尽管C#具有出色的COM互操作支持,但它需要在C#中重新声明相关的COM接口,或者可能使用后期绑定的dynamic魔术。 However, both of these options are rather non-trivial for a project the size of 7z, so on second thought it's likely best to stick with your C++/CLI wrapper approach. 但是,对于7z大小的项目,这两个选项都相当重要,因此,第二个想法是,最好还是坚持使用C ++ / CLI包装器方法。

Within that example, you can see exactly how main does it: It loads the DLL (using a wrapper class NDLL::CLibrary around the LoadLibrary call), then obtains a pointer to the COM CreateObject function (via the same wrapper that does a GetProcAddress internally). 在该示例中,您可以确切地了解它的main NDLL::CLibrary :加载DLL(使用LoadLibrary调用周围的包装器类NDLL::CLibrary ),然后获取指向COM CreateObject函数的指针(通过执行GetProcAddress包装器)内部)。

Once you have the address of the CreateObject function, you can call it with the appropriate application and interface GUIDs to obtain instances of objects that implement them, after which you can use those objects to do the actual work. 获得CreateObject函数的地址后,可以使用适当的应用程序和接口GUID调用它,以获取实现它们的对象的实例,然后您可以使用这些对象进行实际的工作。 The interfaces themselves are declared in header files such as IArchive.h . 接口本身在IArchive.h头文件中声明。

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

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