void CFunc::GbkToUtf8(CString &strGBK)
{
int len = MultiByteToWideChar(CP_ACP, , (LPCTSTR)strGBK, -, NULL, );
unsigned short *wszUtf8 = new unsigned short[len + ];
memset(wszUtf8, , len * + );
MultiByteToWideChar(CP_ACP, , (LPCTSTR)strGBK, -, wszUtf8, len);
len = WideCharToMultiByte(CP_UTF8, , wszUtf8, -, NULL, , NULL, NULL);
char *pszUtf8 = new char[len + ];
memset(pszUtf8, , len + );
WideCharToMultiByte(CP_UTF8, , wszUtf8, -, pszUtf8, len, NULL, NULL);
strGBK = (CString)pszUtf8; delete []pszUtf8;
delete []wszUtf8;
return;
}void CFunc::Utf8ToGbk(CString &strUtf8)
{
int len = MultiByteToWideChar(CP_UTF8, , (LPCTSTR)strUtf8, -, NULL, );
unsigned short *wszGBK = new unsigned short[len + ];
memset(wszGBK, , len * + );
MultiByteToWideChar(CP_UTF8, , (LPCTSTR)strUtf8, -, wszGBK, len);
len = WideCharToMultiByte(CP_ACP, , wszGBK, -, NULL, , NULL, NULL);
char *pszGBK = new char[len + ];
memset(pszGBK, , len + );
WideCharToMultiByte(CP_ACP, , wszGBK, -, pszGBK, len, NULL, NULL);
strUtf8 = (CString)pszGBK; delete []pszGBK;
delete []wszGBK;
return;
}long CFunc::PackHttp(const char *URL, const char *fileName)
{
FILE *fp = NULL;
char *buffer = new char[MAXBUF];
ULONG nBytesRead = ;
CString strRead = "";
ULONG lTotal = ; CInternetSession session(NULL, , INTERNET_OPEN_TYPE_DIRECT, NULL, );
CStdioFile *pFile = NULL; memset(buffer, , sizeof(buffer));
fp = fopen(fileName, "wb"); try
{
pFile = session.OpenURL(URL, , INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_RELOAD);
if (!pFile)
{
fclose(fp);
::DeleteFile(fileName);
delete []buffer;
return -;
}
nBytesRead = pFile->Read(buffer, MAXBUF - );
while (nBytesRead > )
{
lTotal += nBytesRead;
fwrite(buffer, , nBytesRead, fp);
memset(buffer, , sizeof(buffer));
nBytesRead = pFile->Read(buffer, MAXBUF - );
}
}
catch (CInternetException *e)
{
fclose(fp);
::DeleteFile(fileName);
e->Delete();
return - ;
}
fclose(fp);
return lTotal;
}