By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,280 Members | 2,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,280 IT Pros & Developers. It's quick & easy.

Shell Compressed Folder

P: n/a
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>
---

Thanks.
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: http://www.nesterovsky-bros.com



Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> 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?
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: http://www.nesterovsky-bros.com
Nov 17 '05 #2

P: n/a
Vladimir Nesterovsky wrote:
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?


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

http://www.zlib.net/

-cd
Nov 17 '05 #3

P: n/a
> 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?
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: http://www.nesterovsky-bros.com
Nov 17 '05 #4

P: n/a
Vladimir Nesterovsky wrote:
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?


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

http://www.zlib.net/

-cd
Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.