Click to See Complete Forum and Search --> : Using RasEnumConnections
akia
Jan 4th, 2002, 05:49 AM
Could someone please assist me with this code, I have tried to create this from the help file and even though it compliles correctly, the RasEnumConnections API call will not return the correct results. My code is as follows.
{
int ReturnCode =0;
unsigned long *lpcb =0, *lpcConnections =0;
unsigned long *my_hRasConn =0;
RASCONN *lpRasConn[255];
lpRasConn[0]->dwSize = sizeof(RASCONN);
ReturnCode = RasEnumConnections(lpRasConn[0], lpcb, lpcConnections);
if(ReturnCode == ERROR_SUCCESS)
{
RasHangUp(lpRasConn);
}
my_hRasConn = my_hRasConn;
}
Thankyou
CornedBee
Jan 6th, 2002, 10:48 AM
MSDN: (does nobody EVER take a look at it?)
Return Values
If the function succeeds, the return value is zero.
If the function fails, the return value is a nonzero error value listed in the RAS header file or one of ERROR_BUFFER_TOO_SMALL or ERROR_NOT_ENOUGH_MEMORY.
Chris
Jan 9th, 2002, 03:29 AM
try this :)
LPRASENTRYNAME lpRasEntryName;
//
DWORD cEntries=0;
DWORD cb=0;
//
long idx=0;
// Create new RASENTRYNAME structure
lpRasEntryName = (LPRASENTRYNAME)GlobalAlloc(GPTR, sizeof(RASENTRYNAME));
// Initialize the RASENTRYNAME structure
lpRasEntryName->dwSize = sizeof(RASENTRYNAME);
// Get the entry name from registry
idx = RasEnumEntries(NULL, NULL, lpRasEntryName, &cb, &cEntries);
// Out of memory + relocate the RASENTRYNAME structure size
if (idx == ERROR_BUFFER_TOO_SMALL)
{
lpRasEntryName = (LPRASENTRYNAME)GlobalAlloc(GPTR, cb);
lpRasEntryName->dwSize = sizeof(RASENTRYNAME);
}
// Calling RasEnumEntries to enumerate the phone-book entries
idx = RasEnumEntries(NULL, NULL, lpRasEntryName, &cb, &cEntries);
// Error checking
if (idx != ERROR_SUCCESS)
{
// Notify user about the failure.
MessageBox(hWnd, TEXT("Fail to load the RasDial entry from registry!"), TEXT("MyRasDial Error"), MB_OK | MB_ICONEXCLAMATION);
// Set the return value
return 0;
}
else
{
// Loop through the return RASENTRYNAME structure
for(idx=0; idx < (long)cEntries; idx++)
{
// Add the ras entry into the comboboz control
SendDlgItemMessage(hWnd, IDC_COMBO1, CB_INSERTSTRING, -1, (LPARAM)lpRasEntryName->szEntryName);
lpRasEntryName++;
}
}
// Set the return value
return (long)cEntries;
CornedBee
Jan 9th, 2002, 07:51 AM
GlobalAlloc is only kept for compatibility with 16-bit windows. You should use HeapAlloc instead.
Chris
Jan 9th, 2002, 09:20 AM
I'll try out with HeapAlloc later :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.