这是部分代码:
BOOL CUser_ipDlg::Enumuser(LPNETRESOURCE lpNetRC_p)
{
DWORD dwScope = RESOURCE_GLOBALNET ;
DWORD dwType = RESOURCETYPE_ANY ;
HANDLE hNet = 0;
DWORD dwResult = ::WNetOpenEnum(dwScope,dwType,0,lpNetRC_p, &hNet) ;
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;
do
{
lpnrLocal = (LPNETRESOURCE) GlobalAlloc( GPTR, dwBuffer ) ;

dwResult = ::WNetEnumResource(hNet,&dwEntries,lpnrLocal,&dwBuffer) ;

if( dwResult == NO_ERROR )
{
for( DWORD i = 0 ; i < dwEntries ; i++ )
{
CString nsname;
nsname = lpnrLocal[i].lpRemoteName;
if(lpnrLocal[i].dwDisplayType == RESOURCEDISPLAYTYPE_SERVER)
{
nsname=nsname.Right(nsname.GetLength()-2);
m_list.InsertItem(i+1,nsname);
}
if( RESOURCEUSAGE_CONTAINER ==(lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER) &&
lpnrLocal[i].dwDisplayType != RESOURCEDISPLAYTYPE_SERVER ) 
if( !Enumuser( &lpnrLocal[i]) )
return FALSE;

}
} else if( dwResult != ERROR_NO_MORE_ITEMS ) 
return FALSE;
} while( dwResult != ERROR_NO_MORE_ITEMS );

if( lpnrLocal )
GlobalFree((HGLOBAL) lpnrLocal) ;
::WNetCloseEnum(hNet) ;
return bRet;
}void CUser_ipDlg::GetIP()
{
if(m_list.GetItemCount()<=1)
return;
CString m_user;
hostent *Me_Info;
for(int i=0;i<m_list.GetItemCount();i++)
{
m_user=m_list.GetItemText(i,0);
Me_Info=::gethostbyname(m_user);
if(Me_Info!=NULL)
m_list.SetItemText(i,1,::inet_ntoa(*(struct in_addr*)Me_Info->h_addr_list[0]));
}
}