Article View: borland.public.cppbuilder.nativeapi
Article #10673Re: RAS
From: Remy Lebeau (TeamB)
Date: Wed, 07 Apr 2004 18:44
Date: Wed, 07 Apr 2004 18:44
64 lines
3011 bytes
3011 bytes
"Babak" <babak_info@hot.pop> wrote in message
news:40744246@newsgroups.borland.com...
> it just show me garbages like:(not exactly)
That is because you are not checking the return value of RasEnumEntries()
before accessing the values. I will bet you that the function is actually
failing, probably with ERROR_BUFFER_TOO_SMALL, and you are ignoring it.
> RASENTRYNAME* entries = new RASENTRYNAME[1];
You are allocating an array that can only contain 1 RAS entry. Chances are,
there are multiple entries available but you are not allocating enough
storage space to contain them all. Use a larger array, ie:
RASENTRYNAME entries[256];
entries[0].dwSize = sizeof(RASENTRYNAME);
DWORD numEntries = 0;
DWORD size = sizeof(entries);
DWORD res = RasEnumEntries(NULL, NULL, entries, &size, &numEntries);
if( res == 0 ) // <-- always check return values!!!!!
{
for(DWORD i = 0; i < numEntries; ++i)
ShowMessage(entries[i].szEntryName);
}
Or alternatively dynamically allocate the array based on the actual number
of entries that RasEnumEntries() returns, ie:
RASENTRYNAME *entries = (RASENTRYNAME*) LocalAlloc(LPTR,
sizeof(RASENTRYNAME));
if( entries != NULL )
{
entries[0].dwSize = sizeof(RASENTRYNAME);
DWORD numEntries = 0;
DWORD size = entries[0].dwSize;
DWORD res = RasEnumEntries(NULL, NULL, entries, &size, &numEntries);
if( res == ERROR_BUFFER_TOO_SMALL )
{
LocalFree(entries);
entries = (RASENTRYNAME*) LocalAlloc(LPTR, size);
if( entries != NULL )
{
entries[0].dwSize = sizeof(RASENTRYNAME);
numEntries = 0;
res = RasEnumEntries(NULL, NULL, entries, &size,
&numEntries);
}
}
if( res == 0 )
{
for(DWORD i = 0; i < numEntries; ++i)
ShowMessage(entries[i].szEntryName);
}
if( entries != NULL )
LocalFree(entries);
}
Gambit
Technical Details
Message-ID:
<40744bf3$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!zen.net.uk!dedekind.zen.co.uk!news.moat.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40744246@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,5fa49b49fea22a15 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-04-07 12:10:31 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <40744246@newsgroups.borland.com> Subject: Re: RAS Date: Wed, 7 Apr 2004 11:44:12 -0700 Lines: 66 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 67.22.138.253 Message-ID: <40744bf3$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1081363443 67.22.138.253 (7 Apr 2004 11:44:03 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!zen.net.uk!dedekind.zen.co.uk!news.moat.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail