
Introduction
This program acts as a "Network Neighbourhood" which shows all the systems connected to a network of a particular workgroup. You can use this code as a part of a your networking program.
Using the code
Before using this code include Netapi32.lib in Project Settings(Alt+F7)->Links->Object/library modules. Also include the header file
"netserv.h" and "netservDlg.h". The main function or class used is NetServerEnum.
#include "netserv.h"
#include "netservDlg.h"
LPSERVER_INFO_101 pBuf = NULL; DWORD dwServerType = SV_TYPE_SERVER; NET_API_STATUS nStatus;
nStatus = NetServerEnum(NULL,
dwLevel,
(LPBYTE *) &pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
dwServerType,
NULL,
&dwResumeHandle);
If the call succeeds it will return a BOOL value in the form of
NET_API_STATUS. All the names would be taken into a buffer and then listed in the
list box.
Points of Interest
- After
NetServerEnum() call, convert pTmpBuf->sv101_name
to wchar_t type using swprintf().
<br>
wchar_t szWcharBuf[100]; <br>
swprintf(szWcharBuf, L"Name: %s\n", pTmpBuf->sv101_name);
- Use this
wchar_t buffer in WideCharToMultiByte()
API. The second argument should be this flag WC_NO_BEST_FIT_CHARS.
That's it; you will get the ANSI string as out parameter.
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