PDA

View Full Version : 7-Zip DLL usage problems (QLibrary, QUuid GUID conversion, interfaces)



whipsnap
18th April 2010, 21:31
Hi,

I'm trying to write a program that would use 7-Zip DLL for reading files from inside archive files (7z, zip etc).

Here's where I'm so far:




#include <QtCore/QCoreApplication>
#include <QLibrary>
#include <QUuid>
#include <iostream>

using namespace std;

#include "7z910/CPP/7zip/Archive/IArchive.h"
#include "7z910/CPP/7zip/IStream.h"
#include "MyCom.h"

// {23170F69-40C1-278A-1000-000110070000}
QUuid CLSID_CFormat7z(0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);


typedef int (*CreateObjectFunc)(
const GUID *clsID,
const GUID *interfaceID,
void **outObject);

void readFileInArchive()
{
QLibrary myLib("7z.dll");

CreateObjectFunc myFunction = (CreateObjectFunc)myLib.resolve("CreateObject");
if (myFunction == 0) {
cout << "CreateObject resolve failed!";
return;
}
else {
cout << "CreateObject resolved";
}

CMyComPtr<IOutArchive> outArchive;
myFunction(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive);
}



int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

readFileInArchive();

return a.exec();
}



Trying to build that in Qt Creator will lead to following error:
"cannot convert 'QUuid*' to 'const GUID*' in argument passing"

How should QUuid be correctly used in this context?

Also, being a C++ and Qt newbie I haven't yet quite grasped templates or interfaces, so overall I'm having trouble getting through these first steps. If someone could give tips or even example code on how for example an image file could be extracted from ZIP file (to be shown in Qt GUI later on*), I would highly appreciate that.

* My main goal at the moment is to write a program with GUI for selecting archive files containing image files (PNG, JPG etc) and displaying those files one at a time in the GUI. A Qt based CDisplayEx in short.

whipsnap
21st April 2010, 19:12
user chalup from Stackoverflow.com:


You have to explicitly cast QUuid to GUID:


QUuid boo;
GUID uid = static_cast<GUID>(boo);

This worked! Thanks to chalup for the answer.

spacer2004
12th May 2010, 13:55
Hi,

can you extract files from the zip-file with use the 7-zip DLL? If you can do this, can you share you source?

Thanks.