Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2005

Tip: Looking for answers? Try searching our database.

Shell Compressed Folder

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vladimir Nesterovsky - 30 Jun 2005 15:44 GMT
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: vladimir@nesterovsky-bros.com
home: http://www.nesterovsky-bros.com
Vladimir Nesterovsky - 01 Jul 2005 12:49 GMT
> 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
[quoted text clipped - 7 lines]
>
> 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?
Signature

Vladimir Nesterovsky
e-mail: vladimir@nesterovsky-bros.com
home: http://www.nesterovsky-bros.com

Carl Daniel [VC++ MVP] - 01 Jul 2005 15:11 GMT
>> 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
[quoted text clipped - 20 lines]
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.