Lord_Q
May 7th, 2003, 09:36 AM
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.
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.