WNetEnumResourceA function (winnetwk.h)

The WNetEnumResource function continues an enumeration of network resources that was started by a call to the WNetOpenEnum function.


DWORD WNetEnumResourceA(
  [in]      HANDLE  hEnum,
  [in, out] LPDWORD lpcCount,
  [out]     LPVOID  lpBuffer,
  [in, out] LPDWORD lpBufferSize


[in] hEnum

Handle that identifies an enumeration instance. This handle must be returned by the WNetOpenEnum function.

[in, out] lpcCount

Pointer to a variable specifying the number of entries requested. If the number requested is –1, the function returns as many entries as possible.

If the function succeeds, on return the variable pointed to by this parameter contains the number of entries actually read.

[out] lpBuffer

Pointer to the buffer that receives the enumeration results. The results are returned as an array of NETRESOURCE structures. Note that the buffer you allocate must be large enough to hold the structures, plus the strings to which their members point. For more information, see the following Remarks section.

The buffer is valid until the next call using the handle specified by the hEnum parameter. The order of NETRESOURCE structures in the array is not predictable.

[in, out] lpBufferSize

Pointer to a variable that specifies the size of the lpBuffer parameter, in bytes. If the buffer is too small to receive even one entry, this parameter receives the required size of the buffer.

Return value

If the function succeeds, the return value is one of the following values.

Return code Description
The enumeration succeeded, and the buffer contains the requested data. The calling application can continue to call WNetEnumResource to complete the enumeration.
There are no more entries. The buffer contents are undefined.

If the function fails, the return value is a system error code, such as one of the following values.

Return code Description
More entries are available with subsequent calls. For more information, see the following Remarks section.
The handle specified by the hEnum parameter is not valid.
The network is unavailable. (This condition is tested before hEnum is tested for validity.)
A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function.


The WNetEnumResource function does not enumerate users connected to a share; you can call the NetConnectionEnum function to accomplish this task. To enumerate hidden shares, call the NetShareEnum function.

An application cannot set the lpBuffer parameter to NULL and retrieve the required buffer size from the lpBufferSize parameter. Instead, the application should allocate a buffer of a reasonable size—16 kilobytes is typical—and use the value of lpBufferSize for error detection.


For a code sample that illustrates an application-defined function that enumerates all the resources on a network, see Enumerating Network Resources.


The winnetwk.h header defines WNetEnumResource as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.


Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll

See also




Windows Networking (WNet) Overview

Windows Networking Functions