Salut
Suite a cette discution
j'ai teste les codes proposes dans ces trois liens
Celui de CGI fonctionne tres bien, le deuxieme code du site fait un teste permanent de la connection a l'aide d'un Timer, le troisieme code ne fonctionne pas mais je n'ai pas cherche a le Debuger, par contre j'ai utilise la facon de tester le Type de connection, voici le code, sur la Form un Button un TLabel
le .cpp
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 //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { typedef BOOL (WINAPI *PF_INETGETCONNECTEDSTATE)(LPDWORD, DWORD); HANDLE hWinInet; PF_INETGETCONNECTEDSTATE pfInternetGetConnectedState; //............. hWinInet = LoadLibrary("WININET.DLL"); //Chargement de la dll if(hWinInet == NULL) { Label1->Caption = "Impossible de charger Wininet.dll"; return; } pfInternetGetConnectedState = (PF_INETGETCONNECTEDSTATE) GetProcAddress( hWinInet, "InternetGetConnectedState"); // affectation du pointeur sur la fonction if(pfInternetGetConnectedState == NULL) { Label1->Caption = "Erreur appel fonction InternetGetConnectedState"; if(hWinInet) FreeLibrary(hWinInet); return; } //............. DWORD TypeCon ; if (pfInternetGetConnectedState(&TypeCon, 0)) //appel de la fonction { Label1->Caption = "Connecté"; if (TypeCon & INTERNET_CONNECTION_LAN) Label1->Caption = "LAN - Connecté"; if (TypeCon & INTERNET_CONNECTION_MODEM) Label1->Caption = "MODEM actif - Connecté"; if (TypeCon & INTERNET_CONNECTION_PROXY) Label1->Caption = "PROXY-SERVER - Connecté"; } else Label1->Caption = "Déconnecté"; // ............. // Suite du programme a executer // ............. if(hWinInet) FreeLibrary(hWinInet); //libération de la dll } //---------------------------------------------------------------------------
Partager