Board index » delphi » RAS API calls in Delphi 2.0

RAS API calls in Delphi 2.0

Hi!, I am trying to use RAS API calls with Delphi 2.0(no patches) but
the RasEnumEntries always return with the code 610 (ERROR_INVALID_BUFFER),
I set the size of the RasEntryName as the literature says but nothing
works, no matter what size I assign to the dwSize of RasEntry fields, it
always come up with error code 610 as result. I think that the problem
lies in my version of Delphi, because any other tools downloaded and
already compiled work perfectly.

  I am using Windows 95 ver [4.00.950].

  Any help would be greatly appreciated.

  thanks in advance.

  -Felipe.

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet

 

Re:RAS API calls in Delphi 2.0


Quote
fel...@cantv.net wrote:

> Hi!, I am trying to use RAS API calls with Delphi 2.0(no patches) but
> the RasEnumEntries always return with the code 610
> (ERROR_INVALID_BUFFER),

The problem is that it's an insane API. Allocate a really large buffer
(big enough for all Entry-Names) and set the dwSize parameter in the
first element. Then pass this buffer to RasEnumEntries. When it returns,
it will tell you how big a buffer you need...!

Chris.

Re:RAS API calls in Delphi 2.0


I think I saw a component about RAS (maybe a header file... ?) on the
SuperPage.
You can check it out...

Marc-Etienne AKA MParkEt.

Re:RAS API calls in Delphi 2.0


Quote
fel...@cantv.net wrote:

> Hi!, I am trying to use RAS API calls with Delphi 2.0(no patches) but
> the RasEnumEntries always return with the code 610
> (ERROR_INVALID_BUFFER),
Chris Rankin wrote:
> The problem is that it's an insane API.

I've revised my opinion slightly; the API isn't insane, it's just
bad. The following code works:

procedure ExamineRASPhonebookEntries;
var
  RetVal: DWORD;
  RasEntryName, ShowEntryName: PRasEntryName;
  RasEntryNameSize: DWORD;
  RasEntryNameCount: DWORD;
  Initial: TRasEntryName;
begin
  Initial.dwSize := SizeOf(Initial);
  RasEntryNameSize := SizeOf(TRasEntryName);
  RetVal := RasEnumEntries(Nil,Nil,
                           @Initial,
                           RasEntryNameSize,
                           RasEntryNameCount);
  if RetVal = ERROR_BUFFER_TOO_SMALL then
    begin
      GetMem(RasEntryName,RasEntryNameSize);
      try
       RasEntryName^.dwSize := SizeOf(RasEntryName^);
       RetVal := RasEnumEntries(Nil,Nil,
                                RasEntryName,
                                RasEntryNameSize,
                                RasEntryNameCount);
       Writeln( 'RetVal=', RetVal, ' Buffer Size=', RasEntryNameSize );
       if RetVal = NO_ERROR then
         begin
           ShowEntryName := RasEntryName;
           while RasEntryNameCount <> 0 do
             begin
               Writeln( ShowEntryName^.szEntryName );
               Inc(ShowEntryName);
               Dec(RasEntryNameCount)
             end
         end
      finally
        FreeMem(RasEntryName)
      end
    end
end;

Chris.

Other Threads