更改代码 将下面代码用户级别倒叙插入链表:do // begin do { // 调用NetLocalGroupEnum 参数设置与NetLocalGroup类似 nStatus = NetLocalGroupEnum( NULL, dwLevel, (LPBYTE*)&pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, (PDWORD_PTR)&dwResumeHandle); if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)) { if ((pTmpBuf = pBuf) != NULL) { for (int i = 0; i < dwEntriesRead; i++) { //pTmpBuf = pBuf + dwEntriesRead - i; assert(pTmpBuf != NULL); if (pTmpBuf == NULL) { break; } CString csSID = GetSystemSID(pTmpBuf->grpi0_name); if (csSID.Compare(_T("S-1-5-32-544")) == 0) { listAdminGroup.AddTail(pTmpBuf->grpi0_name); } else { if(CheckDisplayGroup(csSID)) { UserLevel* plevel = new UserLevel; plevel->nLevel = plist.GetCount(); _tcsncpy_s(plevel->LevelName,32,pTmpBuf->grpi0_name,31); plist.AddTail(plevel); } } pTmpBuf++; dwTotalCount++; } } } // 释放内存 if (pBuf != NULL) { NetApiBufferFree(pBuf); pBuf = NULL; } }while (nStatus == ERROR_MORE_DATA); // end do
时间: 2024-03-17 09:44:43 浏览: 100
链表的创建、数据的插入、数据的删除以及数据的查询等操作(代码+文档)
更改后的代码如下:
```c++
do // begin do
{
// 调用NetLocalGroupEnum 参数设置与NetLocalGroup类似
nStatus = NetLocalGroupEnum(
NULL,
dwLevel,
(LPBYTE*)&pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
(PDWORD_PTR)&dwResumeHandle);
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
for (int i = 0; i < dwEntriesRead; i++)
{
//pTmpBuf = pBuf + dwEntriesRead - i;
assert(pTmpBuf != NULL);
if (pTmpBuf == NULL)
{
break;
}
CString csSID = GetSystemSID(pTmpBuf->grpi0_name);
if (csSID.Compare(_T("S-1-5-32-544")) == 0)
{
listAdminGroup.AddTail(pTmpBuf->grpi0_name);
}
else
{
if (CheckDisplayGroup(csSID))
{
UserLevel* plevel = new UserLevel;
plevel->nLevel = plist.GetCount();
_tcsncpy_s(plevel->LevelName, 32, pTmpBuf->grpi0_name, 31);
plist.InsertHead(plevel); // 将用户级别插入链表头部
}
}
pTmpBuf++;
dwTotalCount++;
}
}
}
// 释放内存
if (pBuf != NULL)
{
NetApiBufferFree(pBuf);
pBuf = NULL;
}
} while (nStatus == ERROR_MORE_DATA); // end do
```
更改的内容是将用户级别插入链表的方式从原来的 `plist.AddTail(plevel)` 改为 `plist.InsertHead(plevel)`,这样就能够将用户级别倒序插入链表了。
阅读全文