扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
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; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者