Introduction
This application is used as net send message in Windows. This application retrieves all the usernames in LAN into a listbox and user can select any username and sendmessage. By this application, no need to remember all the usernames in LAN.
void CNetworkDlg::DisplayUsers()
{
m_list.ResetContent();
nUsers=0;
CString str;
struct HostInfo
{
char *csName;
char *csAdr;
char *csComment;
};
struct hostent *host;
struct in_addr *ptr;
DWORD dwScope = RESOURCE_CONTEXT;
NETRESOURCE *NetResource = NULL;
HANDLE hEnum;
WNetOpenEnum(dwScope, NULL, NULL, NULL, &hEnum);
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2),&wsaData);
UINT item = 0;
if (hEnum)
{
DWORD Count = 0xFFFFFFFF;
DWORD BufferSize = 2048*8;
LPVOID Buffer = new char[2048*8];
WNetEnumResource(hEnum, &Count, Buffer, &BufferSize);
NetResource = (NETRESOURCE*)Buffer;
char szHostName[200];
for (UINT i = 0; i < BufferSize/sizeof(NETRESOURCE);
i++, NetResource++)
{
if (NetResource->dwUsage == RESOURCEUSAGE_CONTAINER
&& NetResource->dwType == RESOURCETYPE_ANY)
{
if (NetResource->lpRemoteName)
{
CString strFullName = NetResource->lpRemoteName;
char buf[512];
if (0 == strFullName.Left(2).Compare("\\\\"))
strFullName =
strFullName.Right(strFullName.GetLength()-2);
m_list.AddString(strFullName);
nUsers++;
}
}
WNetCloseEnum(hEnum);
}
WSACleanup();
CString st;
st.Format("Total Users:%d",nUsers);
SetDlgItemText(IDC_STATIC1,st);
}
}
History
- 2nd December, 2004: Initial post
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here