用GetLastError()查一下是什么错。ERROR_NOT_CONTAINER The lpNetResource parameter does not point to a container. ERROR_INVALID_PARAMETER Either the dwScope or dwType parameter is invalid, or there is a bad combination of parameters. ERROR_NO_NETWORK No network is present. ERROR_EXTENDED_ERROR A network-specific error occurred. To get a description of the error, use the WNetGetLastError function.
要是在一个网段中倒是不多!
关于这两个函数的用法,请参见MSDN。
用WNetEnumResource()该函数还要牵涉其它函数;
能否给个例子
LPNETRESOURCE lpnr = (LPNETRESOURCE)nr;
DWORD dwSize = sizeof(nr);
HANDLE hRs;
DWORD dwRn = WNetOpenEnum(RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
RESOURCEUSAGE_CONNECTABLE,
lpnr, &hRs);
DWORD dwCount = 1;
while (dwRn == NO_ERROR)
{
dwRn = WNetEnumResource(hRs, &dwCount, (LPNETRESOURCE)nr, &dwSize);
if(dwRn == NO_ERROR)
{
......
// 看一下NETRESOURCE数据结构就可以知道怎么取name了
}
}WNetCloseEnum(hRs);
试过后,立即给分!!!!!!!
为何执行WNetOpenEnum()不成功?
#include "Winnetwk.h"
The lpNetResource parameter does not point to a container.
ERROR_INVALID_PARAMETER
Either the dwScope or dwType parameter is invalid, or there is a bad combination of parameters.
ERROR_NO_NETWORK
No network is present.
ERROR_EXTENDED_ERROR
A network-specific error occurred. To get a description of the error, use the WNetGetLastError function.