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