/*
压缩是一个高深的算法,可以是是计算机科学.
令我等文盲望而止步.
干编程且可不知压缩,大多数人都是用的开源的算法(库).
这万不得已而用之,其实我也不想用.
知道WIN 8有压缩的函数.
前些时断发现XP也有,只是一COM的形式提供.
不错,就是不知它啥时候把活干完,
这是改进之处.
函数还有待改进,如返回的类型,错误的判断,但是实验是正确的可用的.
made by correy
made at 2013.12.23
email:kouleguan at hotmail dot com
homepage:http://correy.webs.com
*/
#include <ShlDisp.h>
#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib")
void zip(BSTR source,BSTR dest)
/*
source可以是文件也可以是文件夹.
dest的后缀名必须是ZIP.
*/
{
//确保source目录存在.
if (!PathFileExists(source))
{
return;
}
// Create Zip file
BYTE startBuffer[] = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
HANDLE hFile = CreateFile(dest, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);//L"C:\\test.zip"
if (hFile == INVALID_HANDLE_VALUE) {
printf("Could not open file (error %d)\n", GetLastError());
return;
}
DWORD dwResult;
if(!WriteFile (hFile, startBuffer, sizeof(startBuffer), &dwResult, NULL))
{
printf("Could not write to file (error %d)\n", GetLastError());
return;
}
if (!CloseHandle(hFile))
{
printf("Could not close to file (error %d)\n", GetLastError());
return;
}
CoInitialize(NULL);
IShellDispatch * pISD;
HRESULT hResult = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&pISD);
if (SUCCEEDED(hResult))
{
VARIANT vDir;
VariantInit(&vDir);
vDir.vt = VT_BSTR;
vDir.bstrVal = dest;//L"C:\\test.zip\\\0\0";
Folder * pToFolder = NULL;
hResult = pISD->NameSpace(vDir, &pToFolder);
if (SUCCEEDED(hResult))
{
VARIANT vFile, vOpt;
VariantInit(&vFile);
vFile.vt = VT_BSTR;
vFile.bstrVal = source;//L"C:\\test.txt";
VariantInit(&vOpt);
vOpt.vt = VT_I4;
vOpt.lVal = FOF_NO_UI;//4; // Do not display a progress dialog box, not useful in our example
// Now copy source file(s) to the zip
// ******NOTE**** To copy multiple files into the zip, need to create a FolderItems object (see unzip implementation below for more details)
hResult = pToFolder->CopyHere(vFile, vOpt);// Copying and compressing the source files to our zip
/* CopyHere() creates a separate thread to copy files and it may happen that the main thread exits before the copy thread is initialized.
So we put the main thread to sleep for a second to give time for the copy thread to start.*/
Sleep(1000);
pToFolder->Release();
}
pISD->Release();
}
CoUninitialize();
}
void unzip(BSTR source,BSTR dest)
/*
把一个ZIP压缩文件解压到指定的文件夹.
*/
{
//确保dest目录存在.
if (!PathFileExists(dest))
{
return;
}
CoInitialize(NULL);
IShellDispatch * pISD;
HRESULT hResult = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&pISD);
if (SUCCEEDED(hResult))
{
VARIANT vDir;
VariantInit(&vDir);
vDir.vt = VT_BSTR;
vDir.bstrVal = dest;//L"C:\\test.zip\\\0\0";
Folder * pToFolder = NULL;
hResult = pISD->NameSpace(vDir, &pToFolder);
if (SUCCEEDED(hResult))
{
VARIANT vFile;
VariantInit(&vFile);
vFile.vt = VT_BSTR;
vFile.bstrVal = source;//L"C:\\test.txt";
Folder * pFromFolder = NULL;
pISD->NameSpace(vFile, &pFromFolder);
FolderItems * fi = NULL;
pFromFolder->Items(&fi);
VARIANT vOpt;
VariantInit(&vOpt);
vOpt.vt = VT_I4;
vOpt.lVal = FOF_NO_UI;//4; // Do not display a progress dialog box
// Creating a new Variant with pointer to FolderItems to be copied
VARIANT newV;
VariantInit(&newV);
newV.vt = VT_DISPATCH;
newV.pdispVal = fi;
hResult = pToFolder->CopyHere(newV, vOpt);
Sleep(1000);
pFromFolder->Release();
pToFolder->Release();
}
pISD->Release();
}
CoUninitialize();
}
int main()
{
zip(L"d:\\test1", L"d:\\test.zip");//\0\0 \\\0\0
unzip(L"d:\\test.zip", L"d:\\test2");//\\\0\0 \\\0\0
return 0;
}
2013年12月23日星期一
2013年12月13日星期五
win8的特殊启动方式
本文是关于win8的特殊启动方式.
最简单的有效的方式是:运行->msconfig.
不过这个只能是安全模式,调试模式等.
特别说明:在WIN 8 X64下,虽然成功的以调试模式启动了,但必须处于调试模式下(也就是连接到了调试器),才能加载驱动.这是个人经验.
禁用签名的办法有:
1.命令行:
bcdedit -set loadoptions DDISABLE_INTEGRITY_CHECKS
bcdedit -set TESTSIGNING ON
需要管理员的权限.
恢复的命令为:
bcdedit -set loadoptions ENABLE_INTEGRITY_CHECKS
bcdedit -set TESTSIGNING OFF
2.Windows8系统下:
键盘按键[Win]+[C]调出系统的超级按钮Charm菜单->设置->更改电脑设置->常规->高级启动(立即重启)->疑难解答->高级选项->启动设置->重新启动,
然后等系统自己加载,就可以进入高级启动菜单界面了,看到“禁用驱动程序强制签名”,选择它就行。算是成功禁用了。
3.Windows8.1系统操作有些不同:
盘按键[Win]+[C]调出系统的超级按钮Charm菜单->设置->更改电脑设置->更新和恢复->恢复->高级启动(立即重启)->操作都一样了~
这个内容摘自:http://www.wenzige.com/post/win8-disable-enable_integrity_checks.html.
最简单的有效的方式是:运行->msconfig.
不过这个只能是安全模式,调试模式等.
特别说明:在WIN 8 X64下,虽然成功的以调试模式启动了,但必须处于调试模式下(也就是连接到了调试器),才能加载驱动.这是个人经验.
禁用签名的办法有:
1.命令行:
bcdedit -set loadoptions DDISABLE_INTEGRITY_CHECKS
bcdedit -set TESTSIGNING ON
需要管理员的权限.
恢复的命令为:
bcdedit -set loadoptions ENABLE_INTEGRITY_CHECKS
bcdedit -set TESTSIGNING OFF
2.Windows8系统下:
键盘按键[Win]+[C]调出系统的超级按钮Charm菜单->设置->更改电脑设置->常规->高级启动(立即重启)->疑难解答->高级选项->启动设置->重新启动,
然后等系统自己加载,就可以进入高级启动菜单界面了,看到“禁用驱动程序强制签名”,选择它就行。算是成功禁用了。
3.Windows8.1系统操作有些不同:
盘按键[Win]+[C]调出系统的超级按钮Charm菜单->设置->更改电脑设置->更新和恢复->恢复->高级启动(立即重启)->操作都一样了~
这个内容摘自:http://www.wenzige.com/post/win8-disable-enable_integrity_checks.html.
订阅:
博文 (Atom)