Skip to content

Instantly share code, notes, and snippets.

@evandroamparo
Created January 25, 2016 17:46
Show Gist options
  • Save evandroamparo/80c1b79337b575eda1de to your computer and use it in GitHub Desktop.
Save evandroamparo/80c1b79337b575eda1de to your computer and use it in GitHub Desktop.
Detect network connection
unit unet;
interface
uses
Windows;
const
NETWORK_ALIVE_LAN = $1;
NETWORK_ALIVE_WAN = $2;
NETWORK_ALIVE_AOL = $4;
type
tagQOCINFO = record
dwSize: DWORD;
dwFlags: DWORD;
dwInSpeed: DWORD;
dwOutSpeed: DWORD;
end;
{$EXTERNALSYM tagQOCINFO}
QOCINFO = ^tagQOCINFO;
{$EXTERNALSYM QOCINFO}
LPQOCINFO = ^QOCINFO;
{$EXTERNALSYM LPQOCINFO}
// TQocInfo = QOCINFO;
// PQocInfo = LPQOCINFO;
function IsDestinationReachableA(lpszDestination: LPCSTR; lpQOCInfo: QOCINFO): BOOL; stdcall;
{$EXTERNALSYM IsDestinationReachableA}
function IsDestinationReachableW(lpszDestination: LPCWSTR; lpQOCInfo: QOCINFO): BOOL; stdcall;
{$EXTERNALSYM IsDestinationReachableW}
function IsDestinationReachable(lpszDestination: LPCTSTR; lpQOCInfo: QOCINFO): BOOL; stdcall;
{$EXTERNALSYM IsDestinationReachable}
function IsNetworkAlive(out lpdwFlags: DWORD): BOOL; stdcall;
{$EXTERNALSYM IsNetworkAlive}
implementation
function IsNetworkAlive(out lpdwFlags: DWORD): BOOL; stdcall;
external 'sensapi.dll' name 'IsNetworkAlive';
function IsDestinationReachableA(lpszDestination: LPCSTR; lpQOCInfo: QOCINFO): BOOL; stdcall;
external 'sensapi.dll' name 'IsDestinationReachableA';
function IsDestinationReachableW(lpszDestination: LPCWSTR; lpQOCInfo: QOCINFO): BOOL; stdcall;
external 'sensapi.dll' name 'IsDestinationReachableW';
function IsDestinationReachable(lpszDestination: LPCTSTR; lpQOCInfo: QOCINFO): BOOL; stdcall;
external 'sensapi.dll' name 'IsDestinationReachable';
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment