Poloczenie z internetem.

0

Jak sprawdzic czy jest się polaczonym z internetem? I jezeli nie polaczyc. Najlepiej w WinAPI.
Ale prosze nie podawac metody spinguj jakis serwer, wiem ze w winapi istnieje taka funkcja tylko nie moge jej znaleŹĆ

0

Uwielbiam cenzurować całe teamaty :D

A jak ktoś jeszcze będzie pisał takie bzdury, to...

0

Wykrywanie połączenia z Internetem.

   Skorzystamy tutaj z biblioteki RAS /Remote Access Services/: 

//-------------------------------------------------------
//w nagłówku
//-------------------------------------------------------

#include
#include
#include
#include
#pragma warn -dup
#define WINVER 0x400
#include
#define WINVER 0x500

class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject Sender);
private: // User declarations
HRASCONN hRas;
bool SprawdzPolaczenie();
public: // User declarations
__fastcall TForm1(TComponent
Owner);
};

//-------------------------------------------------------
//w źródle
//-------------------------------------------------------

typedef DWORD (__stdcall *pRasEnumConnections)
(LPRASCONN, LPDWORD, LPDWORD);

pRasEnumConnections fRasEnumConnections;

HINSTANCE hRasInstance;

__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
hRas = 0;
hRasInstance = LoadLibrary("RASAPI32.DLL");

if (!hRasInstance)
{
ShowMessage("Nie mogę załadować RAS DLL.");
return;
}

fRasEnumConnections = (pRasEnumConnections)
GetProcAddress(hRasInstance, "RasEnumConnectionsA");

if (!fRasEnumConnections) ShowMessage("Błąd ładowania funkcji RAS");
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
FreeLibrary(hRasInstance);
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
bool connected = SprawdzPolaczenie();
if (!connected) ShowMessage("Brak połączenia!");
else ShowMessage ("Mam połączenie!!!");
}

bool TForm1::SprawdzPolaczenie()
{
RASCONN rc;
rc.dwSize = sizeof(RASCONN);
DWORD numConns;
DWORD size = rc.dwSize;
DWORD res = fRasEnumConnections(&rc, &size, &numConns);
if (!res && numConns == 0) return false;
else return true;
}

źródło : forum Borlanda, tłumaczenie Maciej Frankiewicz

0

Vogel szkoda ze przerwales bo fajny topic byl :-D z tym ptaszkiem....

1 użytkowników online, w tym zalogowanych: 0, gości: 1