cs_aardman
Messages postés
1905
Date d'inscription
mercredi 22 janvier 2003
Statut
Membre
Dernière intervention
17 septembre 2012
3
10 déc. 2003 à 21:34
Salut,
Pour lire un fichier texte sur le net et l'afficher dans une messagebox:
#include <windows.h>
#include <Wininet.h>
#pragma comment(lib, "Wininet.lib")
char szURL[] = "";
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
char * pFile;DWORD dwFileSize 0, dwByteRead 0;
DWORD dwContext = 0;
HINTERNET hSession, hUrl;
hSession = InternetOpen("test", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0);
if(hSession == NULL) return 0;
hUrl = InternetOpenUrl(hSession, szURL, 0, 0, INTERNET_FLAG_EXISTING_CONNECT, (DWORD_PTR)&dwContext);
if(hUrl == NULL) return 0;
InternetQueryDataAvailable(hUrl, &dwFileSize, 0, (DWORD_PTR)&dwContext);
pFile = (char*)malloc(dwFileSize+1);
memset(pFile, 0, dwFileSize);
InternetReadFile(hUrl, pFile, dwFileSize, &dwByteRead);
pFile[dwByteRead] = 0;
MessageBox(0, pFile, "le fichier", 0);
free(pFile);
InternetCloseHandle(hUrl);
InternetCloseHandle(hSession);
return 0;
}