Click here to Skip to main content
Click here to Skip to main content

Network Message

By , 1 Dec 2004
Rate this:
Please Sign up or sign in to vote.

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

License

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

About the Author

Eswar_Illuri
Web Developer
India India
I am working at Virinchi Technologies as programmer in vc++,COM & symbian c++. My hobbies are painting, and play chess and carams.

Comments and Discussions

 
GeneralUI for net send PinsussMsftone21-Jan-05 23:09 
GeneralHI Eswar PinmemberThatsAlok3-Dec-04 19:21 
GeneralFull Progam PinsussAnonymous2-Dec-04 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 2 Dec 2004
Article Copyright 2004 by Eswar_Illuri
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid