typedef struct _NETRESOURCE { // nr DWORD dwScope; DWORD dwType; DWORD dwDisplayType; DWORD dwUsage; LPTSTR lpLocalName; LPTSTR lpRemoteName; LPTSTR lpComment; LPTSTR lpProvider; } NETRESOURCE; |
bool __fastcall TForm1::EnumerateFunc(HWND hwnd ,LPNETRESOURCE lpnr,TTreeNode * ParentNode) { DWORD dwResult, dwResultEnum; HANDLE hEnum; DWORD cbBuffer = 16384; /* 16K is reasonable size */ DWORD cEntries = 0xFFFFFFFF; /* enumerate all possible entries */ LPNETRESOURCE lpnrLocal; /* pointer to enumerated structures */ DWORD i; dwResult = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, /* enumerate all resources */ lpnr, /* NULL first time this function is called */ &hEnum); /* handle to resource */ if (dwResult ==67) //domain下没有可访问的主机 return true; if (dwResult != NO_ERROR ) { //无 ShowError(dwResult); return false; } TTreeNode * Child; do { lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer); dwResultEnum = WNetEnumResource(hEnum, /* resource handle */ &cEntries, /* defined locally as 0xFFFFFFFF */ lpnrLocal, /* LPNETRESOURCE */ &cbBuffer); /* buffer size */ if (dwResultEnum == NO_ERROR) { for(i = 0; i < cEntries; i++) { Child=TreeView1->Items->AddChild(ParentNode,lpnrLocal[i].lpRemoteName); if(RESOURCEUSAGE_c o nTAINER == (lpnrLocal[i].dwUsage & RESOURCEUSAGE_c o nTAINER)) if(!EnumerateFunc(this->Handle, &lpnrLocal[i],Child)) ShowMessage("EnumerateFunc returned FALSE."); } } else if (dwResultEnum != ERROR_NO_MORE_ITEMS) { ShowError(dwResultEnum); break; } } while(dwResultEnum != ERROR_NO_MORE_ITEMS); GlobalFree((HGLOBAL) lpnrLocal); dwResult = WNetCloseEnum(hEnum); if(dwResult != NO_ERROR) { ShowError(dwResult); return FALSE; } return true; } |
欢迎访问最专业的网吧论坛,无盘论坛,网吧经营,网咖管理,网吧专业论坛
https://bbs.txwb.com
关注天下网吧微信/下载天下网吧APP/天下网吧小程序,一起来超精彩
|
本文来源:yesky 作者:佚名