Article ID: 198801 - Last Review: April 30, 2004 - Revision: 3.2

BUG: RasEnumEntries returns success regardless of buffer size

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
This article was previously published under Q198801
Expand all | Collapse all

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 that this is a problem in the Microsoft products that are listed in the "Applies to" section.

APPLIES TO
  • Microsoft Windows CE 2.0 for the Handheld PC
  • Microsoft Windows CE 1.0
Keywords: 
kbbug kbpending KB198801