1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| char * pFile;
DWORD dwFileSize = 0, dwByteRead = 0;
DWORD dwContext = 0;
char szURL[] = "http://.....";
HINTERNET hSession, hUrl;
hSession = InternetOpen("test", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0);
if(hSession == NULL) {MessageBox (hDlg, "Erreur de connexion Internet ...." , "Erreur", NULL); return 0;}
hUrl = InternetOpenUrl(hSession, szURL, 0, 0, INTERNET_FLAG_EXISTING_CONNECT, (DWORD_PTR)&dwContext); if(hUrl == NULL) {MessageBox (hDlg, "Erreur de connexion internet !" , "Erreur", NULL); return 0;}
if(!InternetQueryDataAvailable(hUrl, &dwFileSize, 0, (DWORD_PTR)&dwContext)){MessageBox (hDlg, "Erreur de connexion internet" , "Erreur", NULL);}
pFile = (char*)malloc(dwFileSize+1);
memset(pFile, 0, dwFileSize);
if(!InternetReadFile(hUrl, pFile, dwFileSize, &dwByteRead)){MessageBox (hDlg, "Erreur de connexion internet" , "Erreur", NULL);}
pFile[dwByteRead] = 0;
InternetCloseHandle(hUrl);
InternetCloseHandle(hSession);
ofstream log("protsock.log");
log << pFile;
SetDlgItemText(hDlg, 155, pFile);
free(pFile); |
Partager