简体   繁体   中英

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

I am trying to use 7zip from within my application code. On 7zip's website, they say I can use 7z.dll. So, I tried to reference it from C#, but that didn't work. So, I decided to write a C++ library that references 7z.dll, and then I can reference that library from 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.

However, I don't know how to figure out the method names inside the 7z.dll library so that I can call them.

Please help

Hmm, Hans Passant pointed out SevenZipSharp which makes my answer rather useless ;-) I'll leave it for purely educational purposes. No need to write your own COM interop wrappers if somebody else has already done it for you...


I had a look at their C++ example (under CPP/7zip/UI/Client7z). Everything is done using COM interfaces and various types of callbacks.

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. 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.

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).

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. The interfaces themselves are declared in header files such as IArchive.h .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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