bon, j'ai opté pour un test en thread,

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
 
p_threadConnected = AfxBeginThread (threadFunction,  this);
 
...
 
UINT threadFunction (LPVOID pParam)
{
 
	while( TRUE )
	{
		TestConnexion();
 
		Sleep(50);
	}
 
	return 0;
}
 
...
 
BOOL TestConnexion(void)
{
 
	DWORD flags;
	HINTERNET hInternetSession, hHttpSession;
	flags = INTERNET_CONNECTION_OFFLINE;
	BOOL connected = InternetGetConnectedState(&flags, 0);
 
	//if (connected) connected = ! InternetCheckConnection("http://www.google.fr", INTERNET_CONNECTION_OFFLINE, 0);
 
	if (connected)
	{
		connected = FALSE;
		hInternetSession = InternetOpen ("test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL) ;
		if (hInternetSession)
		{
			hHttpSession  = InternetOpenUrl( hInternetSession, "http://www.google.com", NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0 ) ;
			connected = hHttpSession !=  FALSE;
			if (connected) InternetCloseHandle( hHttpSession );
		}
		InternetCloseHandle (hInternetSession) ;
	}
 
	return connected;
 
}
Par contre; bizarrement, quand la connexion est mise en erreur (chg de dns ou deconnexion du reseau) la fonction InternetOpenUrl semble bloquée,

comment lui définir un timeout ?