Shell Compressed Folder

  • Thread starter Vladimir Nesterovsky
  • Start date
V

Vladimir Nesterovsky

Hello,

I'm having a trouble with a Shell.Folder object when I'm trying to use it
from a C++ application, but at the same time, the same object works fine
from within html script.

The effect is that, I cannot put data into a compressed folder in C++, in
spite of the fact that all operations succeed.

Note: all this have to work under XP and above, because of integrated
compressed folder shell object.

I appreciate any hint to a what causes this behavior.

It is given:
c:\temp\data.txt - any text file.
c:\temp\data.zip - empty zip file
(compress data.txt manualy, and then remove it from within zip).

C++ program:
---
#import <shell32.dll> named_guids
#include <iostream>

class CoInit
{
public:
CoInit() { CoInitialize(0); }
~CoInit() { CoUninitialize(); }
};

bool CompressFile()
{
try
{
Shell32::IShellDispatchPtr shell(Shell32::CLSID_Shell);
Shell32::FolderPtr destinationFolder =
shell->NameSpace(L"c:\\temp\\data.zip");

if (destinationFolder == 0)
return false;

if (destinationFolder->MoveHere(L"c:\\temp\\data.txt") != S_OK)
return false;

return true;
}
catch(const _com_error &e)
{
std::cout << e.ErrorMessage() << std::endl;

return false;
}
}

int main(int argc, char* argv[])
{
CoInit coInit;
bool result = CompressFile();

std::cout << (result ? "succeed" : "failed") << std::endl;

return 0;
}

---

Html file:
---
<html>
<head>
<script type="text/javascript" language="javascript">

function doClick()
{
var shell = new ActiveXObject("Shell.Application");
var folder = shell.NameSpace("c:\\temp\\data.zip");

if (folder == null)
return false;

folder.MoveHere("c:\\temp\\data.txt");

return true;
}

</script>
</head>
<body>
<button onclick="doClick()">Click me</button>
</body>
</html>
 
V

Vladimir Nesterovsky

I'm having a trouble with a Shell.Folder object when I'm trying to use it
from a C++ application, but at the same time, the same object works fine
from within html script.

The effect is that, I cannot put data into a compressed folder in C++, in
spite of the fact that all operations succeed.

Note: all this have to work under XP and above, because of integrated
compressed folder shell object.

I appreciate any hint to a what causes this behavior.

Well, I've figured out what happens. Shell32::Folder::MoveHere works in an
asynchronous way. This means that operation returns immediately with succeed
code if all parameters are correct, however the actual work is performed
later in a separate thread. This way C++ application exits before it
actually
started the work, and html application succeeds as it's continue running.
Unfortunately, I have found no an easy way to get completion event.

After all, it must be not the easiest way to compress files from the
application. Therefore my question for now is how would I create zip from my
unmanaged application?
 
C

Carl Daniel [VC++ MVP]

Vladimir said:
Well, I've figured out what happens. Shell32::Folder::MoveHere works
in an asynchronous way. This means that operation returns immediately
with succeed code if all parameters are correct, however the actual
work is performed later in a separate thread. This way C++
application exits before it actually
started the work, and html application succeeds as it's continue
running. Unfortunately, I have found no an easy way to get completion
event.

After all, it must be not the easiest way to compress files from the
application. Therefore my question for now is how would I create zip
from my unmanaged application?

ZLIB is your friend (it's what the shell uses under the covers).

http://www.zlib.net/

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top