CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2003
    Location
    UK
    Posts
    4

    NetServerEnum problem (Tricky)***RESOLVED***

    I'm having a problem with netserverenum. It seems to only return the first character fo each server and on examination the memory is filled. However each letter is followed by a null char and each item is terminated by 3 nulls. i can't seem to get the full names to return for me. My code is below and the memory during execution is at the end:

    LPSERVER_INFO_101 pBuf = NULL;
    LPSERVER_INFO_101 pTmpBuf;
    DWORD dwLevel = 101;
    DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
    DWORD dwEntriesRead = 0;
    DWORD dwTotalEntries = 0;
    DWORD dwResumeHandle = 0;
    NET_API_STATUS nStatus;
    LPCWSTR pszServerName = NULL;
    LPTSTR pName = NULL;
    int lvIndex = 0;
    DWORD i;


    nStatus = NetServerEnum(pszServerName,
    dwLevel,
    (LPBYTE *) &pBuf,
    dwPrefMaxLen,
    &dwEntriesRead,
    &dwTotalEntries,
    dwServerType,
    NULL,
    &dwResumeHandle);
    //
    // If the call succeeds,
    //
    if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
    {
    if ((pTmpBuf = pBuf) != NULL)
    {
    //
    // Loop through the entries and
    // print the data for all server types.
    //
    for (i = 0; i < dwEntriesRead; i++)
    {
    assert(pTmpBuf != NULL);

    if (pTmpBuf == NULL)
    {
    MessageBox("Error enumerating servers - null pointer received",NULL,MB_ICONEXCLAMATION);
    break;
    }



    if (primDomain)
    {
    m_DomainCombo.AddString(pTmpBuf->sv101_name);
    }
    else
    {

    m_hostList.InsertItem(lvIndex,pTmpBuf->sv101_name);
    lvIndex++;
    }

    pTmpBuf++;
    }
    // Display a warning if all available entries were
    // not enumerated, print the number actually
    // enumerated, and the total number available.

    if (nStatus == ERROR_MORE_DATA)
    {
    m_infoLbl = "Not all entries enumerated" + (CString)lvIndex + " complete ";
    }
    else
    {
    m_infoLbl = "Found: " + lvIndex;
    }
    }
    }
    else
    m_infoLbl = (CString)nStatus;
    //
    // Free the allocated buffer.
    //
    if (pBuf != NULL)
    NetApiBufferFree(pBuf);

    UpdateData(false);
    return 0;

    Memory after NetServerenum completes

    00155A26 41 00 44 00 4D 00 49 A.D.M.I
    00155A2D 00 4E 00 00 00 AB AB .N...««
    00155A34 AB AB AB AB AB AB EE ««««««î
    00155A3B FE EE FE EE FE 00 00 þîþîþ..
    00155A42 00 00 00 00 00 00 B7 ......·
    00155A49 0C 4D 01 00 14 EE FE .M...îþ
    00155A50 78 01 14 00 D0 3F 15 x...Ð?.
    00155A57 00 EE FE EE FE EE FE .îþîþîþ

    Any help would be appreciated.
    Last edited by Lord_Q; May 8th, 2003 at 04:39 AM.
    The only problem with inventing something idiot proof is that sooner or later someone just invents a better idiot!!!

    Stop the Earth i wanna get off!!!

  2. #2
    Join Date
    May 2003
    Location
    UK
    Posts
    4
    Just for those of you who come up against theis probelm i have found the solution.

    The memory shown is filled with widechars and so needs converted.

    I found that adding a secong buffer:

    char nameBuf[ CNLEN + 1 ] ;

    and a line to convert the data:

    WideCharToMultiByte(CP_ACP,0,pName,-1,nameBuf,UNLEN,NULL,NULL);

    where pName = (LPWSTR)pTmpBuf->sv101_name;

    this sorts my problem out

    DOH!!!

    Cheers to those who viewed and tried to help
    The only problem with inventing something idiot proof is that sooner or later someone just invents a better idiot!!!

    Stop the Earth i wanna get off!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured