用VC列表显示所有网上邻居

来源:本站
导读:目前正在解读《用VC列表显示所有网上邻居》的相关信息,《用VC列表显示所有网上邻居》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《用VC列表显示所有网上邻居》的详细说明。
简介:本文给大家分享了用VC列表显示所有网上邻居的原代码。

#include <winnetwk.h>

#pragma comment(lib, “mpr.lib”)

BOOL CNetEnum2Dlg::Enumerate(LPNETRESOURCE lpNetRC_p)

{

HANDLE hEnum = 0;

DWORD dwScope = RESOURCE_GLOBALNET ;

DWORD dwType = RESOURCETYPE_ANY ;

DWORD dwResult = WNetOpenEnum(

dwScope, // scope of enumeration

dwType, // resource types to list

0, // enumerate all resources

lpNetRC_p, // pointer to resource structure (NULL at first time)

&hEnum // handle to resource

) ;

if( dwResult != NO_ERROR )

return FALSE;

DWORD dwBuffer = 16384 ; // 16K is reasonable size

DWORD dwEntries = 0xFFFFFFFF ; // enumerate all possible entries

LPNETRESOURCE lpnrLocal = 0;

BOOL bRet = TRUE;

//try

{

do

{

// first allocate buffer for NETRESOURCE structures ...

lpnrLocal = (LPNETRESOURCE) GlobalAlloc( GPTR, dwBuffer ) ;

dwResult = WNetEnumResource(

hEnum, // resource-handle

&dwEntries,

lpnrLocal,

&dwBuffer

) ;

if( dwResult == NO_ERROR )

{

for( register DWORD i = 0 ; i

{

CString nsname;

nsname = lpnrLocal[i].lpRemoteName;

nsname += " ";

nsname +=lpnrLocal[i].lpLocalName;

nsname += " ";

nsname +=lpnrLocal[i].lpComment;

m_netList.AddString(nsname); // m_netList defined in NetEnumDlg2.h : CListBox m_netList;

if( RESOURCEUSAGE_CONTAINER ==

(lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER) &&

lpnrLocal[i].dwDisplayType != RESOURCEDISPLAYTYPE_SERVER )

if( !Enumerate( &lpnrLocal[i]) )

{

//TRACE0( "CNetwork::Enumerate(): recursiv call failedn" );

//throw CNetworkBreak(FALSE);

return FALSE;

}

}

} else if( dwResult != ERROR_NO_MORE_ITEMS )

{

//AfxMessageBox("WNetEnumResource");

return FALSE;

}

} while( dwResult != ERROR_NO_MORE_ITEMS );

}

if( lpnrLocal )

GlobalFree((HGLOBAL) lpnrLocal) ;

WNetCloseEnum(hEnum) ;

return bRet;

}

void CNetEnum2Dlg::OnListWNet()

{

Enumerate(0);

}

提醒:《用VC列表显示所有网上邻居》最后刷新时间 2024-03-14 00:58:35,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《用VC列表显示所有网上邻居》该内容的真实性请自行鉴别。