程序使用第三方的XUNZIP进行文件解压,封装自己的解压函数,如下:
void CMyUnZip::MyUnZip( char* szPathAndFileName, char* szUnZipPath )
{
char buffer[248]; if(szUnZipPath != NULL)
{
/* 如果文件路径不存在 先创建,存在 不做任何修改 */
//SHCreateDirectoryEx(NULL, szUnZipPath, NULL);
}
else
{
GetCurrentDirectory(248, (LPWSTR)&buffer);
szUnZipPath = buffer;
//SHCreateDirectoryEx(NULL, szUnZipPath, NULL);
} HZIP hz = OpenZip( (void*)szPathAndFileName, 0, ZIP_FILENAME);
ZIPENTRYW ze; 
GetZipItem(hz, -1, &ze); 
int numitems=ze.index; char strUnZipPath[300];
char szPath[260]={0};
for (int zi=0; zi<numitems; zi++)

ZIPENTRYW ze; 
GetZipItem(hz,zi,&ze);

WcharToChar(ze.name, szPath, 260);
                meset(strUnZipPath, 0, 300);
strcpy(strUnZipPath, szUnZipPath);
                strcat(strUnZipPath, zaPath)

UnzipItem(hz, zi, (void*)strUnZipPath, 0,ZIP_FILENAME);         
szFilePath.push_back(strUnZipPath);
} CloseZip(hz);
} [/code]程序在HZIP hz = OpenZip( (void*)szPathAndFileName, 0, ZIP_FILENAME);这地方就一直出错,打开失败?请问这个究竟是怎么一回事?
最原始版本做的时候两个参数是用的CString类型,即MyUnZip( CString szPathAndFileName, CString szUnZipPath ),然后OpenZip的时候是HZIP hz=OpenZip( (void*)(LPTSTR)(LPCTSTR)szPathAndFileName, 0, ZIP_FILENAME);  这样做的时候却是正常没问题的。
C++解压缩

解决方案 »

  1.   

    (void*)szPathAndFileName 这个参数转换估计有问题
      

  2.   

    参数传递错误了吧
    HZIP OpenZip(const TCHAR *fn, const char *password);
    HZIP OpenZip(void *z,unsigned int len, const char *password);
    HZIP OpenZipHandle(HANDLE h, const char *password);
    // OpenZip - opens a zip file and returns a handle with which you can
    // subsequently examine its contents. You can open a zip file from:
    // from a pipe:             OpenZipHandle(hpipe_read,0);
    // from a file (by handle): OpenZipHandle(hfile,0);
    // from a file (by name):   OpenZip("c:\\test.zip","password");