BUG: RasEnumEntries Returns Success Regardless of Buffer Size

ID: Q198801


The information in this article applies to:


SYMPTOMS

On Windows CE, RasEnumEntries is used to list all entry names in a remote access phone book. However, it returns 0 (success) even if you put a zero for the size of the input buffer parameter. The correct behavior should return ERROR_BUFFER_TOO_SMALL.


RESOLUTION

To work around the problem, we can pre-allocate a large buffer to receive phone book entries and use the out parameter "lpcEntries" to enumerate the phone book entries.

Following is sample code:


void OnRasenum()

{

    DWORD cb = 0;
    DWORD cEntries = 0;
    DWORD dwRet;
    DWORD i;
    TCHAR szBuf[1024];
    LPRASENTRYNAME lpRasEntryName = NULL;

    // Pre-alloate a sufficient large buffer for 10 phone book entries.
    lpRasEntryName = (LPRASENTRYNAME) LocalAlloc(LPTR, 10 *
                                                  sizeof(RASENTRYNAME));
    if (lpRasEntryName == NULL)
        return;
    lpRasEntryName->dwSize = sizeof(RASENTRYNAME);
    cb = 10 * sizeof(RASENTRYNAME);

    dwRet = RasEnumEntries(NULL, NULL, lpRasEntryName, &cb, &cEntries);
    if (dwRet == ERROR_BUFFER_TOO_SMALL)
    {
        LocalFree(lpRasEntryName);
        lpRasEntryName = NULL;
        lpRasEntryName = (LPRASENTRYNAME) LocalAlloc(LPTR, cb);
        if (lpRasEntryName == NULL)
            return;
        lpRasEntryName->dwSize = sizeof(RASENTRYNAME);

        if (RasEnumEntries(NULL, NULL, lpRasEntryName, &cb, &cEntries)
                                                                      != 0)
        {
            LocalFree(lpRasEntryName);
            return;
        }
    }
    else if (dwRet != 0)
    {
        LocalFree(lpRasEntryName);
        return;
    }


    // RasEnumEntries success

    wsprintf(szBuf, _T("Phone book entries [%d] in the default \ phonebook:"), cEntries);
    MessageBox(NULL, szBuf, _T("RasEnumEntries"), MB_OK);
    for(i=0;i < cEntries;i++)
    {
        wsprintf(szBuf, _T("%s"),lpRasEntryName->szEntryName);
        MessageBox(NULL, szBuf, _T("RasEnumEntries"), MB_OK);
        lpRasEntryName++;
    }
    if (lpRasEntryName)
        LocalFree(lpRasEntryName);
    return;

} 


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

Additional query words:


Keywords          : kbWinCE100bug kbWinCE200bug 
Version           : WINDOWS:1.0,2.0
Platform          : WINDOWS 
Issue type        : kbbug 

Last Reviewed: February 20, 1999