Thread View: comp.os.ms-windows.programmer.win32
3 messages
3 total messages
Started by Vic Metcalfe
Sun, 18 Jan 1998 00:00
RasEnumConnections always returns 0 entries
Author: Vic Metcalfe
Date: Sun, 18 Jan 1998 00:00
Date: Sun, 18 Jan 1998 00:00
51 lines
2513 bytes
2513 bytes
I am trying to get a list of active RAS connections on an NT 4.0 RAS
server. I'm programming with Delphi 3.0, but if that's the problem I
can switch to VC++ 4.0. Every time I call RasEnumConnections, it
returns 0 (no error) but does not list any active connections. If I run
the Remote Access Admin however, it correctly lists the connections. In
the code example below, the third showmessage shows that bufsize,
numconnections and result are all zero.
I've looked for help on Dejanews, but everyone seems to be talking about
detecting and/or initiating RAS connections on the client side.
Shouldn't this be the same as detecting client side connections? It
seems to me that this should be a really easy task, and I must be
missing something really simple. I hope someone will be able to point
out the error to me!
Thanks in advance,
Vic.
function TForm1.UpdateConnectList:longint;
var
n:longint;
bufsize:longint;
RASConnect: Array[1..500] OF TRASConn;
NumConnections: DWord;
RASEvent:Word;
begin
RASEvent := RegisterWindowMessage(RASDialEvent);
If RASEvent = 0 THEN
RASEvent := WM_RASDialEvent;
bufsize:=sizeof(RasConnect);
NumConnections:=500;
RasConnect[1].dwSize:=sizeof(TRasConn);
showmessage('Buffer size: '+inttostr(bufsize)+' NumConnections: '+
inttostr(NumConnections));
result:=RasEnumConnections(@RASConnect, BufSize, NumConnections);
if result<>0 then
begin
RasGetErrorString(result,pchar(@rasconnect),sizeof(rasconnect));
showmessage('Error: '+pchar(@rasconnect));
exit;
end;
showmessage('Buffer size: '+inttostr(bufsize)+' NumConnections: '+
inttostr(NumConnections)+' Result: '+inttostr(Result));
ConnectList.items.clear;
for n:=1 to NumConnections do
begin
{ ConnectList is a TListBox on Form1. }
ConnectList.Items.Add(RasConnect[n].szEntryName);
end;
end;
Re: RasEnumConnections always returns 0 entries
Author: John Lockwood
Date: Sun, 18 Jan 1998 00:00
Date: Sun, 18 Jan 1998 00:00
67 lines
2969 bytes
2969 bytes
That's because your passing NumConnections as is to the function,
which expects a pointer to the number. Try passing @NumConnections.
You see, if you want to spot pointer errors, ask a C++ programmer; we
have more experience making them. ;-)
John
Vic Metcalfe <vic@brutus.tlug.org> wrote:
>I am trying to get a list of active RAS connections on an NT 4.0 RAS
>server. I'm programming with Delphi 3.0, but if that's the problem I
>can switch to VC++ 4.0. Every time I call RasEnumConnections, it
>returns 0 (no error) but does not list any active connections. If I run
>the Remote Access Admin however, it correctly lists the connections. In
>the code example below, the third showmessage shows that bufsize,
>numconnections and result are all zero.
>I've looked for help on Dejanews, but everyone seems to be talking about
>detecting and/or initiating RAS connections on the client side.
>Shouldn't this be the same as detecting client side connections? It
>seems to me that this should be a really easy task, and I must be
>missing something really simple. I hope someone will be able to point
>out the error to me!
>Thanks in advance,
> Vic.
>function TForm1.UpdateConnectList:longint;
>var
> n:longint;
> bufsize:longint;
> RASConnect: Array[1..500] OF TRASConn;
> NumConnections: DWord;
> RASEvent:Word;
>begin
> RASEvent := RegisterWindowMessage(RASDialEvent);
> If RASEvent = 0 THEN
> RASEvent := WM_RASDialEvent;
> bufsize:=sizeof(RasConnect);
> NumConnections:=500;
> RasConnect[1].dwSize:=sizeof(TRasConn);
> showmessage('Buffer size: '+inttostr(bufsize)+' NumConnections: '+
> inttostr(NumConnections));
> result:=RasEnumConnections(@RASConnect, BufSize, NumConnections);
> if result<>0 then
> begin
> RasGetErrorString(result,pchar(@rasconnect),sizeof(rasconnect));
> showmessage('Error: '+pchar(@rasconnect));
> exit;
> end;
> showmessage('Buffer size: '+inttostr(bufsize)+' NumConnections: '+
> inttostr(NumConnections)+' Result: '+inttostr(Result));
> ConnectList.items.clear;
> for n:=1 to NumConnections do
> begin
> { ConnectList is a TListBox on Form1. }
> ConnectList.Items.Add(RasConnect[n].szEntryName);
> end;
>end;
------------------------
John Lockwood Consulting
http://www.jlockwood.com
Re: RasEnumConnections always returns 0 entries
Author: Vic Metcalfe
Date: Sun, 18 Jan 1998 00:00
Date: Sun, 18 Jan 1998 00:00
35 lines
1816 bytes
1816 bytes
John Lockwood wrote:
>
> That's because your passing NumConnections as is to the function,
> which expects a pointer to the number. Try passing @NumConnections.
> You see, if you want to spot pointer errors, ask a C++ programmer; we
> have more experience making them. ;-)
Thanks for your reply John. I should have mentioned that the pointer
parameters would be confusing to c and c++ people. In pascal (or at
least in Delphi, and I think in standard pascal as well) you can declare
a parameter to be a reference, and the compiler will automatically make
it a pointer, so:
procedure double(var x:integer);
begin
x:=x*2;
end;
Would take a reference to an integer and double it. The code calling
the procedure would simply say:
x:=2;
double(x);
{x now should be 4}
The Delphi declaration for RasEnumConnections uses this technique to
hide the referencing and dereferencing from the programmer. I can tell
that this much works correctly because a) it doesn't give an access
violation, and b) the values are set to zero on return.
I'll have a go at this in c and see where it takes me.
Thanks again,
Vic.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads