18,356
社区成员
发帖
与我相关
我的任务
分享
LPCSTR UIAsset::UTF8ToANSI(LPCSTR utf8)
{
int nLen = ::MultiByteToWideChar(CP_UTF8, NULL, utf8, strlen(utf8), NULL, 0);
wchar_t* ucs = new wchar_t[nLen + 1];
::MultiByteToWideChar(CP_UTF8, NULL, utf8, strlen(utf8), ucs, nLen);
ucs[nLen] = '\0';
nLen = ::WideCharToMultiByte(CP_ACP, NULL, ucs, wcslen(ucs), NULL, 0, NULL, NULL);
char* ansi = new char[nLen + 1];
::WideCharToMultiByte(CP_ACP, NULL, ucs, wcslen(ucs), ansi, nLen, NULL, NULL);
ansi[nLen] = '\0';
delete[] ucs;
return ansi;
}
LPCWSTR UTF8ToUCS(LPCSTR utf8)
{
int nLen = ::MultiByteToWideChar(CP_UTF8, NULL, utf8, strlen(utf8), NULL, 0);
wchar_t* ucs = new wchar_t[nLen + 1];
::MultiByteToWideChar(CP_UTF8, NULL, utf8, strlen(utf8), ucs, nLen);
ucs[nLen] = '\0';
return ucs;
}
#include "resource.h"
#include "stdafx.h"
#include<windows.h>
#include<wininet.h>
#pragma comment(lib,"wininet.lib")
#pragma comment(lib,"kernel32.lib")
void Entry();
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
int ret=URLDownloadToFile(NULL,"http://www.google.cn/intl/zh-CN/images/logo_cn.gif",
"c:\\logo.gif",0,NULL);
if (ret==S_OK) //如果下载成功
{
MessageBox(NULL, "okok", "OK", MB_OK);
}
Entry();
return 0;
}
void Entry()
{
HINTERNET hSession=InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
HINTERNET hConnection=InternetOpenUrl(hSession,"http://www.google.com",NULL,0,0,0);
BYTE Buffer[4096];
DWORD Read=0,i;
HANDLE hFile=CreateFile("c:\\index.htm",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
InternetReadFile(hConnection,Buffer,sizeof(Buffer),&Read);
while(Read!=0)
{
WriteFile(hFile,Buffer,Read,&i,NULL);
InternetReadFile(hConnection,Buffer,sizeof(Buffer),&Read);
}
CloseHandle(hFile);
InternetCloseHandle(hConnection);
InternetCloseHandle(hSession);
}
两种方法 可以下载任何东西了。