+static DWORD _enumerateConnectedW(PWNetEnumerator enumerator, LPDWORD lpcCount,
+ LPVOID lpBuffer, LPDWORD lpBufferSize)
+{
+ DWORD ret, index, count, size, i, len, left;
+ PVOID end;
+ LPNETRESOURCEW curr, buffer;
+ PHANDLE handles;
+
+ if (!enumerator)
+ return WN_BAD_POINTER;
+ if (enumerator->enumType != WNET_ENUMERATOR_TYPE_CONNECTED)
+ return WN_BAD_VALUE;
+ if (!lpcCount)
+ return WN_BAD_POINTER;
+ if (!lpBuffer)
+ return WN_BAD_POINTER;
+ if (!lpBufferSize)
+ return WN_BAD_POINTER;
+ if (!providerTable)
+ return WN_NO_NETWORK;
+
+ handles = enumerator->lpBuffer;
+ left = *lpBufferSize;
+ size = *lpBufferSize;
+ buffer = HeapAlloc(GetProcessHeap(), 0, *lpBufferSize);
+ if (!buffer)
+ return WN_NO_NETWORK;
+
+ curr = lpBuffer;
+ end = (PVOID)((ULONG_PTR)lpBuffer + size);
+ count = *lpcCount;
+
+
+ for (index = 0; index < providerTable->numProviders; index++)
+ {
+ if (providerTable->table[index].dwEnumScopes)
+ {
+ if (handles[index] == 0)
+ {
+ ret = providerTable->table[index].openEnum(enumerator->dwScope,
+ enumerator->dwType,
+ enumerator->dwUsage,
+ NULL, &handles[index]);
+ if (ret != WN_SUCCESS)
+ continue;
+ }
+
+ ret = providerTable->table[index].enumResource(handles[index],
+ &count,
+ buffer,
+ &size);
+
+ if (ret == WN_MORE_DATA)
+ {
+
+ break;
+ }
+
+ if (ret == WN_SUCCESS)
+ {
+ for (i = 0; i < count; ++i)
+ {
+ if (left < sizeof(NETRESOURCEW))
+ {
+ ret = WN_MORE_DATA;
+ break;
+ }
+
+ memcpy(curr, &buffer[i], sizeof(NETRESOURCEW));
+ left -= sizeof(NETRESOURCEW);
+
+ len = WideCharToMultiByte(CP_ACP, 0, buffer[i].lpLocalName, -1, NULL, 0, NULL, NULL);
+ len *= sizeof(WCHAR);
+ if (left < len)
+ {
+ ret = WN_MORE_DATA;
+ break;
+ }
+
+ end = (PVOID)((ULONG_PTR)end - len);
+ curr->lpLocalName = end;
+ memcpy(end, buffer[i].lpLocalName, len);
+ left -= len;
+
+ len = WideCharToMultiByte(CP_ACP, 0, buffer[i].lpRemoteName, -1, NULL, 0, NULL, NULL);
+ len *= sizeof(WCHAR);
+ if (left < len)
+ {
+ ret = WN_MORE_DATA;
+ break;
+ }
+
+ end = (PVOID)((ULONG_PTR)end - len);
+ curr->lpRemoteName = end;
+ memcpy(end, buffer[i].lpRemoteName, len);
+ left -= len;
+
+ len = WideCharToMultiByte(CP_ACP, 0, buffer[i].lpProvider, -1, NULL, 0, NULL, NULL);
+ len *= sizeof(WCHAR);
+ if (left < len)
+ {
+ ret = WN_MORE_DATA;
+ break;
+ }
+
+ end = (PVOID)((ULONG_PTR)end - len);
+ curr->lpProvider = end;
+ memcpy(end, buffer[i].lpProvider, len);
+ left -= len;
+
+ ++curr;
+ }
+
+ count = *lpcCount - count;
+ size = left;
+ }
+
+ if (ret != WN_SUCCESS || count == 0)
+ {
+ break;
+ }
+ }
+ }
+
+ if (count == 0)
+ ret = WN_NO_MORE_ENTRIES;
+
+ *lpcCount = *lpcCount - count;
+ if (ret != WN_MORE_DATA && ret != WN_NO_MORE_ENTRIES)
+ ret = WN_SUCCESS;
+
+ HeapFree(GetProcessHeap(), 0, buffer);
+
+ TRACE("Returning %d\n", ret);
+ return ret;
+}
+