Fórum Abrir Conexao de Internet #313132

15/02/2006

0

Galera depois de sofrer mais conseguir com ajuda do forum para enviar e receber dados pela porta serial agora tenho q fazer o seguinte:
Em um label eu infomo o post do cliente e uma porta comunicação 4455 e preciso que ao precionar o botão ele verifica se exite conexão de internet ativa se não ele conecta e faz a conexao de Internet.

Se tiver algum componete OperSorce que me ajudara melhor a fazer isso.


Marcal

Marcal

Responder

Posts

15/02/2006

Paullsoftware

Esse código eu encontrei na net, não testei ainda!

interface 
uses 
Windows, SysUtils, Registry, WinSock, WinInet; 
 
type 
TConnectionType = (ctNone, ctProxy, ctDialup); 
 
function ConnectedToInternet : TConnectionType; 
function RasConnectionCount : Integer; 
 
 
implementation 
 
const 
cERROR_BUFFER_TOO_SMALL = 603; 
cRAS_MaxEntryName = 256; 
cRAS_MaxDeviceName = 128; 
cRAS_MaxDeviceType = 16; 
type 
ERasError = class(Exception); 
 
HRASConn = DWord; 
PRASConn = ^TRASConn; 
TRASConn = record 
dwSize: DWORD; 
rasConn: HRASConn; 
szEntryName: Array[0..cRAS_MaxEntryName] Of Char; 
szDeviceType : Array[0..cRAS_MaxDeviceType] Of Char; 
szDeviceName : Array [0..cRAS_MaxDeviceName] of char; 
end; 
 
TRasEnumConnections = 
function (RASConn: PrasConn; { buffer para receber dados da conexao} 
var BufSize: DWord; { tamanho em bytes do buffer } 
var Connections: DWord { numero de conexoes escritas no buffer } 
): LongInt; stdcall; 
 
 
function ConnectedToInternet: TConnectionType; 
var 
Reg : TRegistry; 
bUseProxy : Boolean; 
UseProxy : LongWord; 
begin 
Result := ctNone; 
Reg := TRegistry.Create; 
with REG do 
try 
try 
RootKey := HKEY_CURRENT_USER; 
if OpenKey(´\Software\Microsoft\Windows\CurrentVersion\Internet settings´,False) then begin 
//I just try to read it, and trap an exception 
if GetDataType(´ProxyEnable´) = rdBinary then 
ReadBinaryData(´ProxyEnable´, UseProxy, SizeOf(LongWord) ) 
else begin 
bUseProxy := ReadBool(´ProxyEnable´); 
if bUseProxy then 
UseProxy := 1 
else 
UseProxy := 0; 
end; 
if (UseProxy <> 0) and ( ReadString(´ProxyServer´) <> ´´ ) then Result := ctProxy; 
end; 
except 
//Nao conectado com proxy 
end; 
finally 
Free; 
end; 
 
if Result = ctNone then begin 
if RasConnectionCount > 0 then Result := ctDialup; 
end; 
end; 
 
function RasConnectionCount : Integer; 
var 
RasDLL : HInst; 
Conns : Array[1..4] of TRasConn; 
RasEnums : TRasEnumConnections; 
BufSize : DWord; 
NumConns : DWord; 
RasResult : Longint; 
begin 
Result := 0; 
 
//Load the RAS DLL 
RasDLL := LoadLibrary(´rasapi32.dll´); 
if RasDLL = 0 then exit; 
 
try 
RasEnums := GetProcAddress(RasDLL,´RasEnumConnectionsA´); 
if @RasEnums = nil then 
raise ERasError.Create(´RasEnumConnectionsA not found in rasapi32.dll´); 
 
Conns[1].dwSize := Sizeof (Conns[1]); 
BufSize := SizeOf(Conns); 
 
RasResult := RasEnums(@Conns, BufSize, NumConns); 
 
If (RasResult = 0) or (Result = cERROR_BUFFER_TOO_SMALL) then Result := NumConns; 
finally 
FreeLibrary(RasDLL); 
end; 
end; 


e aqui faz a chamada para conexão padrão:

uses Registry;

procedure TForm1.Button1Click(Sender: TObject);
Var
Conexao, Executa, Conecta : string;
Dialup : Pchar;
reg : TRegIniFile;
begin
  reg := TRegIniFile.create(´RemoteAccess\´);
  Conexao := reg.ReadString(´´,´Default´,´´);
  reg.free;
  Executa:=´rundll32.exe rnaui.dll,RnaDial ´; {executavel e biblioteca do windows}
  Conecta:=Executa+Conexao; {concatena comando e nome da conexão}
  Dialup:=Pchar(Conecta); {transforma string em caracter para ser aceita pela função}
  winexec(Dialup,sw_show);
end; 


espero ter ajudado!


Responder

Gostei + 0

09/03/2006

Marcal

Amigo ta executando blz mais quando chamo a função no Button da o seguinte erro: ´Erro ao Carregar rnaui.dll Não foi possivél encointrar o modulo especificado´

O que pode ser uso o Wind XP


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar