Bonjour, j'utilise ce code pour recuperer certaines pages web particulieres,

cette fonction est utilisé par plusieurs thread et du coup, peut etre appelée simultanément (ou presque) par plusieures taches en parallele,

la ou je m'interroge, c'est au niveau de la fonction InternetOpen, son premier parametre est fixe, je me demande si cela pose un probleme par rapport a l'appel simultanné avec ce meme parametre.

A votre avis, cela pose t'il un probleme ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
CString GetWebPage(CString url)
{
	#define TAILLE_BUFFER 256
 
	CString sRead = "";	
 
 
	HINTERNET hInternetSession, 
			  hHttpSession;
 
	char buffer[TAILLE_BUFFER];
 
	DWORD dwRead;
 
	DWORD dwSize = 20;
	LPVOID lpOutBuffer = new char[dwSize];
 
 
	hInternetSession = InternetOpen ("test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL) ;
	if (hInternetSession)
    {
	   hHttpSession  = InternetOpenUrl( hInternetSession, url, NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0 ) ;
	   if (!hHttpSession)
	   {
		   InternetCloseHandle (hInternetSession) ;
		   sRead = CST_WEB_RES_BADCONN;
		}
	   else
	   {
		   //*************************************************************************************//
		   //							Lecture du HEADER HTTP									  //
		   //*************************************************************************************//
			sprintf((char *)lpOutBuffer,"Content-Type");
			if(!HttpQueryInfo(hHttpSession,HTTP_QUERY_CUSTOM, (LPVOID)lpOutBuffer,&dwSize,NULL))
			{
				if (GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND)
				{
					// Code to handle the case where the header isn't available.
					sprintf((char *)lpOutBuffer,"");
				}		
				else
				{
					// Check for an insufficient buffer.
					if (GetLastError()==ERROR_INSUFFICIENT_BUFFER)
					{
						sprintf((char *)lpOutBuffer,"Content-Type");				
					}		
					else
					{
						// Error handling code.
						sprintf((char *)lpOutBuffer,"");
					}		
				}		
			}
			if (strcmp("Content-Type", (char *)lpOutBuffer)!=0) // erreur
			{
				if (strcmp("text/bad_pw", (char *)lpOutBuffer)==0)
				{
					sRead = CST_WEB_RES_BADLOG;
				}
				else if (strcmp("text/good_pw", (char *)lpOutBuffer)==0)
				{
					sRead = CST_WEB_RES_GOODLOG;
				}
				else if (strcmp("text/ko", (char *)lpOutBuffer)==0)
				{
					sRead = CST_WEB_RES_SERVERROR;
				}
				else if (strcmp("text/ok", (char *)lpOutBuffer)==0)
				{
					sRead = CST_WEB_RES_OK;
				}
				else if (strcmp("text/plain", (char *)lpOutBuffer)!=0)				
				{
					sRead = CST_WEB_RES_ERROR;
				}
 
			}
			//*************************************************************************************//
 
			if (sRead=="")
			{
				while ( InternetReadFile( hHttpSession, buffer, TAILLE_BUFFER-1, &dwRead ) )
				{
					if ( dwRead == 0 )
						break;
					buffer[dwRead] = 0;
					sRead += buffer;
				}
			}
 
			InternetCloseHandle( hHttpSession );
			InternetCloseHandle (hInternetSession) ;
	   }
   }
 
	delete lpOutBuffer;
 
	return sRead;
}