4 * Copyright 1999 Ulrich Weigand
5 * Copyright 2004 Juan Lang
6 * Copyright 2007 Maarten Lankhorst
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mpr
);
38 /* Data structures representing network service providers. Assumes only one
39 * thread creates them, and that they are constant for the life of the process
40 * (and therefore doesn't synchronize access).
41 * FIXME: only basic provider data and enumeration-related data are implemented
42 * so far, need to implement the rest too.
44 typedef struct _WNetProvider
52 PF_NPOpenEnum openEnum
;
53 PF_NPEnumResource enumResource
;
54 PF_NPCloseEnum closeEnum
;
55 PF_NPGetResourceInformation getResourceInformation
;
56 } WNetProvider
, *PWNetProvider
;
58 typedef struct _WNetProviderTable
63 WNetProvider table
[1];
64 } WNetProviderTable
, *PWNetProviderTable
;
66 #define WNET_ENUMERATOR_TYPE_NULL 0
67 #define WNET_ENUMERATOR_TYPE_GLOBAL 1
68 #define WNET_ENUMERATOR_TYPE_PROVIDER 2
69 #define WNET_ENUMERATOR_TYPE_CONTEXT 3
71 /* An WNet enumerator. Note that the type doesn't correspond to the scope of
72 * the enumeration; it represents one of the following types:
73 * - a 'null' enumeration, one that contains no members
74 * - a global enumeration, one that's executed across all providers
75 * - a provider-specific enumeration, one that's only executed by a single
77 * - a context enumeration. I know this contradicts what I just said about
78 * there being no correspondence between the scope and the type, but it's
79 * necessary for the special case that a "Entire Network" entry needs to
80 * be enumerated in an enumeration of the context scope. Thus an enumeration
81 * of the context scope results in a context type enumerator, which morphs
82 * into a global enumeration (so the enumeration continues across all
85 typedef struct _WNetEnumerator
95 } WNetEnumerator
, *PWNetEnumerator
;
97 #define BAD_PROVIDER_INDEX (DWORD)0xffffffff
99 /* Returns an index (into the global WNetProviderTable) of the provider with
100 * the given name, or BAD_PROVIDER_INDEX if not found.
102 static DWORD
_findProviderIndexW(LPCWSTR lpProvider
);
104 static PWNetProviderTable providerTable
;
107 * Global provider table functions
110 static void _tryLoadProvider(PCWSTR provider
)
112 static const WCHAR servicePrefix
[] = { 'S','y','s','t','e','m','\\',
113 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
114 'S','e','r','v','i','c','e','s','\\',0 };
115 static const WCHAR serviceFmt
[] = { '%','s','%','s','\\',
116 'N','e','t','w','o','r','k','P','r','o','v','i','d','e','r',0 };
117 WCHAR serviceName
[MAX_PATH
];
120 TRACE("%s\n", debugstr_w(provider
));
121 snprintfW(serviceName
, sizeof(serviceName
) / sizeof(WCHAR
), serviceFmt
,
122 servicePrefix
, provider
);
123 serviceName
[sizeof(serviceName
) / sizeof(WCHAR
) - 1] = '\0';
124 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, serviceName
, 0, KEY_READ
, &hKey
) ==
127 static const WCHAR szProviderPath
[] = { 'P','r','o','v','i','d','e','r',
129 WCHAR providerPath
[MAX_PATH
];
130 DWORD type
, size
= sizeof(providerPath
);
132 if (RegQueryValueExW(hKey
, szProviderPath
, NULL
, &type
,
133 (LPBYTE
)providerPath
, &size
) == ERROR_SUCCESS
&& type
== REG_SZ
)
135 static const WCHAR szProviderName
[] = { 'N','a','m','e',0 };
139 RegQueryValueExW(hKey
, szProviderName
, NULL
, NULL
, NULL
, &size
);
142 name
= HeapAlloc(GetProcessHeap(), 0, size
);
143 if (RegQueryValueExW(hKey
, szProviderName
, NULL
, &type
,
144 (LPBYTE
)name
, &size
) != ERROR_SUCCESS
|| type
!= REG_SZ
)
146 HeapFree(GetProcessHeap(), 0, name
);
152 HMODULE hLib
= LoadLibraryW(providerPath
);
156 PF_NPGetCaps getCaps
= (PF_NPGetCaps
)GetProcAddress(hLib
,
159 TRACE("loaded lib %p\n", hLib
);
162 PWNetProvider provider
=
163 &providerTable
->table
[providerTable
->numProviders
];
165 provider
->hLib
= hLib
;
166 provider
->name
= name
;
167 TRACE("name is %s\n", debugstr_w(name
));
168 provider
->getCaps
= getCaps
;
169 provider
->dwSpecVersion
= getCaps(WNNC_SPEC_VERSION
);
170 provider
->dwNetType
= getCaps(WNNC_NET_TYPE
);
171 TRACE("net type is 0x%08x\n", provider
->dwNetType
);
172 provider
->dwEnumScopes
= getCaps(WNNC_ENUMERATION
);
173 if (provider
->dwEnumScopes
)
175 TRACE("supports enumeration\n");
176 provider
->openEnum
= (PF_NPOpenEnum
)
177 GetProcAddress(hLib
, "NPOpenEnum");
178 TRACE("openEnum is %p\n", provider
->openEnum
);
179 provider
->enumResource
= (PF_NPEnumResource
)
180 GetProcAddress(hLib
, "NPEnumResource");
181 TRACE("enumResource is %p\n",
182 provider
->enumResource
);
183 provider
->closeEnum
= (PF_NPCloseEnum
)
184 GetProcAddress(hLib
, "NPCloseEnum");
185 TRACE("closeEnum is %p\n", provider
->closeEnum
);
186 provider
->getResourceInformation
= (PF_NPGetResourceInformation
)
187 GetProcAddress(hLib
, "NPGetResourceInformation");
188 TRACE("getResourceInformation is %p\n",
189 provider
->getResourceInformation
);
190 if (!provider
->openEnum
|| !provider
->enumResource
191 || !provider
->closeEnum
)
193 provider
->openEnum
= NULL
;
194 provider
->enumResource
= NULL
;
195 provider
->closeEnum
= NULL
;
196 provider
->dwEnumScopes
= 0;
197 WARN("Couldn't load enumeration functions\n");
200 providerTable
->numProviders
++;
204 WARN("Provider %s didn't export NPGetCaps\n",
205 debugstr_w(provider
));
206 HeapFree(GetProcessHeap(), 0, name
);
212 WARN("Couldn't load library %s for provider %s\n",
213 debugstr_w(providerPath
), debugstr_w(provider
));
214 HeapFree(GetProcessHeap(), 0, name
);
219 WARN("Couldn't get provider name for provider %s\n",
220 debugstr_w(provider
));
224 WARN("Couldn't open value %s\n", debugstr_w(szProviderPath
));
228 WARN("Couldn't open service key for provider %s\n",
229 debugstr_w(provider
));
232 void wnetInit(HINSTANCE hInstDll
)
234 static const WCHAR providerOrderKey
[] = { 'S','y','s','t','e','m','\\',
235 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
236 'C','o','n','t','r','o','l','\\',
237 'N','e','t','w','o','r','k','P','r','o','v','i','d','e','r','\\',
238 'O','r','d','e','r',0 };
239 static const WCHAR providerOrder
[] = { 'P','r','o','v','i','d','e','r',
240 'O','r','d','e','r',0 };
243 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, providerOrderKey
, 0, KEY_READ
, &hKey
)
248 RegQueryValueExW(hKey
, providerOrder
, NULL
, NULL
, NULL
, &size
);
251 PWSTR providers
= HeapAlloc(GetProcessHeap(), 0, size
);
257 if (RegQueryValueExW(hKey
, providerOrder
, NULL
, &type
,
258 (LPBYTE
)providers
, &size
) == ERROR_SUCCESS
&& type
== REG_SZ
)
263 TRACE("provider order is %s\n", debugstr_w(providers
));
264 /* first count commas as a heuristic for how many to
265 * allocate space for */
266 for (ptr
= providers
, numToAllocate
= 1; ptr
; )
268 ptr
= strchrW(ptr
, ',');
275 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
276 sizeof(WNetProviderTable
)
277 + (numToAllocate
- 1) * sizeof(WNetProvider
));
281 int entireNetworkLen
;
282 LPCWSTR stringresource
;
284 entireNetworkLen
= LoadStringW(hInstDll
,
285 IDS_ENTIRENETWORK
, (LPWSTR
)&stringresource
, 0);
286 providerTable
->entireNetwork
= HeapAlloc(
287 GetProcessHeap(), 0, (entireNetworkLen
+ 1) *
289 if (providerTable
->entireNetwork
)
291 memcpy(providerTable
->entireNetwork
, stringresource
, entireNetworkLen
*sizeof(WCHAR
));
292 providerTable
->entireNetwork
[entireNetworkLen
] = 0;
294 providerTable
->numAllocated
= numToAllocate
;
295 for (ptr
= providers
; ptr
; )
298 ptr
= strchrW(ptr
, ',');
301 _tryLoadProvider(ptrPrev
);
305 HeapFree(GetProcessHeap(), 0, providers
);
318 for (i
= 0; i
< providerTable
->numProviders
; i
++)
320 HeapFree(GetProcessHeap(), 0, providerTable
->table
[i
].name
);
321 FreeModule(providerTable
->table
[i
].hLib
);
323 HeapFree(GetProcessHeap(), 0, providerTable
->entireNetwork
);
324 HeapFree(GetProcessHeap(), 0, providerTable
);
325 providerTable
= NULL
;
329 static DWORD
_findProviderIndexW(LPCWSTR lpProvider
)
331 DWORD ret
= BAD_PROVIDER_INDEX
;
333 if (providerTable
&& providerTable
->numProviders
)
337 for (i
= 0; i
< providerTable
->numProviders
&&
338 ret
== BAD_PROVIDER_INDEX
; i
++)
339 if (!strcmpW(lpProvider
, providerTable
->table
[i
].name
))
349 static LPNETRESOURCEW
_copyNetResourceForEnumW(LPNETRESOURCEW lpNet
)
355 ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(NETRESOURCEW
));
361 ret
->lpLocalName
= ret
->lpComment
= ret
->lpProvider
= NULL
;
362 if (lpNet
->lpRemoteName
)
364 len
= strlenW(lpNet
->lpRemoteName
) + 1;
365 ret
->lpRemoteName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
366 if (ret
->lpRemoteName
)
367 strcpyW(ret
->lpRemoteName
, lpNet
->lpRemoteName
);
376 static void _freeEnumNetResource(LPNETRESOURCEW lpNet
)
380 HeapFree(GetProcessHeap(), 0, lpNet
->lpRemoteName
);
381 HeapFree(GetProcessHeap(), 0, lpNet
);
385 static PWNetEnumerator
_createNullEnumerator(void)
387 PWNetEnumerator ret
= HeapAlloc(GetProcessHeap(),
388 HEAP_ZERO_MEMORY
, sizeof(WNetEnumerator
));
391 ret
->enumType
= WNET_ENUMERATOR_TYPE_NULL
;
395 static PWNetEnumerator
_createGlobalEnumeratorW(DWORD dwScope
, DWORD dwType
,
396 DWORD dwUsage
, LPNETRESOURCEW lpNet
)
398 PWNetEnumerator ret
= HeapAlloc(GetProcessHeap(),
399 HEAP_ZERO_MEMORY
, sizeof(WNetEnumerator
));
403 ret
->enumType
= WNET_ENUMERATOR_TYPE_GLOBAL
;
404 ret
->dwScope
= dwScope
;
405 ret
->dwType
= dwType
;
406 ret
->dwUsage
= dwUsage
;
407 ret
->lpNet
= _copyNetResourceForEnumW(lpNet
);
412 static PWNetEnumerator
_createProviderEnumerator(DWORD dwScope
, DWORD dwType
,
413 DWORD dwUsage
, DWORD index
, HANDLE handle
)
417 if (!providerTable
|| index
>= providerTable
->numProviders
)
421 ret
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WNetEnumerator
));
424 ret
->enumType
= WNET_ENUMERATOR_TYPE_PROVIDER
;
425 ret
->providerIndex
= index
;
426 ret
->dwScope
= dwScope
;
427 ret
->dwType
= dwType
;
428 ret
->dwUsage
= dwUsage
;
429 ret
->handle
= handle
;
435 static PWNetEnumerator
_createContextEnumerator(DWORD dwScope
, DWORD dwType
,
438 PWNetEnumerator ret
= HeapAlloc(GetProcessHeap(),
439 HEAP_ZERO_MEMORY
, sizeof(WNetEnumerator
));
443 ret
->enumType
= WNET_ENUMERATOR_TYPE_CONTEXT
;
444 ret
->dwScope
= dwScope
;
445 ret
->dwType
= dwType
;
446 ret
->dwUsage
= dwUsage
;
451 /* Thunks the array of wide-string LPNETRESOURCEs lpNetArrayIn into buffer
452 * lpBuffer, with size *lpBufferSize. lpNetArrayIn contains *lpcCount entries
453 * to start. On return, *lpcCount reflects the number thunked into lpBuffer.
454 * Returns WN_SUCCESS on success (all of lpNetArrayIn thunked), WN_MORE_DATA
455 * if not all members of the array could be thunked, and something else on
458 static DWORD
_thunkNetResourceArrayWToA(const NETRESOURCEW
*lpNetArrayIn
,
459 const DWORD
*lpcCount
, LPVOID lpBuffer
, const DWORD
*lpBufferSize
)
461 DWORD i
, numToThunk
, totalBytes
, ret
;
465 return WN_BAD_POINTER
;
467 return WN_BAD_POINTER
;
471 return WN_BAD_POINTER
;
473 return WN_BAD_POINTER
;
475 for (i
= 0, numToThunk
= 0, totalBytes
= 0; i
< *lpcCount
; i
++)
477 const NETRESOURCEW
*lpNet
= lpNetArrayIn
+ i
;
479 totalBytes
+= sizeof(NETRESOURCEA
);
480 if (lpNet
->lpLocalName
)
481 totalBytes
+= WideCharToMultiByte(CP_ACP
, 0, lpNet
->lpLocalName
,
482 -1, NULL
, 0, NULL
, NULL
);
483 if (lpNet
->lpRemoteName
)
484 totalBytes
+= WideCharToMultiByte(CP_ACP
, 0, lpNet
->lpRemoteName
,
485 -1, NULL
, 0, NULL
, NULL
);
486 if (lpNet
->lpComment
)
487 totalBytes
+= WideCharToMultiByte(CP_ACP
, 0, lpNet
->lpComment
,
488 -1, NULL
, 0, NULL
, NULL
);
489 if (lpNet
->lpProvider
)
490 totalBytes
+= WideCharToMultiByte(CP_ACP
, 0, lpNet
->lpProvider
,
491 -1, NULL
, 0, NULL
, NULL
);
492 if (totalBytes
< *lpBufferSize
)
495 strNext
= (LPSTR
)((LPBYTE
)lpBuffer
+ numToThunk
* sizeof(NETRESOURCEA
));
496 for (i
= 0; i
< numToThunk
; i
++)
498 LPNETRESOURCEA lpNetOut
= (LPNETRESOURCEA
)lpBuffer
+ i
;
499 const NETRESOURCEW
*lpNetIn
= lpNetArrayIn
+ i
;
501 memcpy(lpNetOut
, lpNetIn
, sizeof(NETRESOURCEA
));
502 /* lie about string lengths, we already verified how many
503 * we have space for above
505 if (lpNetIn
->lpLocalName
)
507 lpNetOut
->lpLocalName
= strNext
;
508 strNext
+= WideCharToMultiByte(CP_ACP
, 0, lpNetIn
->lpLocalName
, -1,
509 lpNetOut
->lpLocalName
, *lpBufferSize
, NULL
, NULL
);
511 if (lpNetIn
->lpRemoteName
)
513 lpNetOut
->lpRemoteName
= strNext
;
514 strNext
+= WideCharToMultiByte(CP_ACP
, 0, lpNetIn
->lpRemoteName
, -1,
515 lpNetOut
->lpRemoteName
, *lpBufferSize
, NULL
, NULL
);
517 if (lpNetIn
->lpComment
)
519 lpNetOut
->lpComment
= strNext
;
520 strNext
+= WideCharToMultiByte(CP_ACP
, 0, lpNetIn
->lpComment
, -1,
521 lpNetOut
->lpComment
, *lpBufferSize
, NULL
, NULL
);
523 if (lpNetIn
->lpProvider
)
525 lpNetOut
->lpProvider
= strNext
;
526 strNext
+= WideCharToMultiByte(CP_ACP
, 0, lpNetIn
->lpProvider
, -1,
527 lpNetOut
->lpProvider
, *lpBufferSize
, NULL
, NULL
);
530 ret
= numToThunk
< *lpcCount
? WN_MORE_DATA
: WN_SUCCESS
;
531 TRACE("numToThunk is %d, *lpcCount is %d, returning %d\n", numToThunk
,
536 /* Thunks the array of multibyte-string LPNETRESOURCEs lpNetArrayIn into buffer
537 * lpBuffer, with size *lpBufferSize. lpNetArrayIn contains *lpcCount entries
538 * to start. On return, *lpcCount reflects the number thunked into lpBuffer.
539 * Returns WN_SUCCESS on success (all of lpNetArrayIn thunked), WN_MORE_DATA
540 * if not all members of the array could be thunked, and something else on
543 static DWORD
_thunkNetResourceArrayAToW(const NETRESOURCEA
*lpNetArrayIn
,
544 const DWORD
*lpcCount
, LPVOID lpBuffer
, const DWORD
*lpBufferSize
)
546 DWORD i
, numToThunk
, totalBytes
, ret
;
550 return WN_BAD_POINTER
;
552 return WN_BAD_POINTER
;
556 return WN_BAD_POINTER
;
558 return WN_BAD_POINTER
;
560 for (i
= 0, numToThunk
= 0, totalBytes
= 0; i
< *lpcCount
; i
++)
562 const NETRESOURCEA
*lpNet
= lpNetArrayIn
+ i
;
564 totalBytes
+= sizeof(NETRESOURCEW
);
565 if (lpNet
->lpLocalName
)
566 totalBytes
+= MultiByteToWideChar(CP_ACP
, 0, lpNet
->lpLocalName
,
567 -1, NULL
, 0) * sizeof(WCHAR
);
568 if (lpNet
->lpRemoteName
)
569 totalBytes
+= MultiByteToWideChar(CP_ACP
, 0, lpNet
->lpRemoteName
,
570 -1, NULL
, 0) * sizeof(WCHAR
);
571 if (lpNet
->lpComment
)
572 totalBytes
+= MultiByteToWideChar(CP_ACP
, 0, lpNet
->lpComment
,
573 -1, NULL
, 0) * sizeof(WCHAR
);
574 if (lpNet
->lpProvider
)
575 totalBytes
+= MultiByteToWideChar(CP_ACP
, 0, lpNet
->lpProvider
,
576 -1, NULL
, 0) * sizeof(WCHAR
);
577 if (totalBytes
< *lpBufferSize
)
580 strNext
= (LPWSTR
)((LPBYTE
)lpBuffer
+ numToThunk
* sizeof(NETRESOURCEW
));
581 for (i
= 0; i
< numToThunk
; i
++)
583 LPNETRESOURCEW lpNetOut
= (LPNETRESOURCEW
)lpBuffer
+ i
;
584 const NETRESOURCEA
*lpNetIn
= lpNetArrayIn
+ i
;
586 memcpy(lpNetOut
, lpNetIn
, sizeof(NETRESOURCEW
));
587 /* lie about string lengths, we already verified how many
588 * we have space for above
590 if (lpNetIn
->lpLocalName
)
592 lpNetOut
->lpLocalName
= strNext
;
593 strNext
+= MultiByteToWideChar(CP_ACP
, 0, lpNetIn
->lpLocalName
,
594 -1, lpNetOut
->lpLocalName
, *lpBufferSize
);
596 if (lpNetIn
->lpRemoteName
)
598 lpNetOut
->lpRemoteName
= strNext
;
599 strNext
+= MultiByteToWideChar(CP_ACP
, 0, lpNetIn
->lpRemoteName
,
600 -1, lpNetOut
->lpRemoteName
, *lpBufferSize
);
602 if (lpNetIn
->lpComment
)
604 lpNetOut
->lpComment
= strNext
;
605 strNext
+= MultiByteToWideChar(CP_ACP
, 0, lpNetIn
->lpComment
,
606 -1, lpNetOut
->lpComment
, *lpBufferSize
);
608 if (lpNetIn
->lpProvider
)
610 lpNetOut
->lpProvider
= strNext
;
611 strNext
+= MultiByteToWideChar(CP_ACP
, 0, lpNetIn
->lpProvider
,
612 -1, lpNetOut
->lpProvider
, *lpBufferSize
);
615 ret
= numToThunk
< *lpcCount
? WN_MORE_DATA
: WN_SUCCESS
;
616 TRACE("numToThunk is %d, *lpcCount is %d, returning %d\n", numToThunk
,
621 /*********************************************************************
622 * WNetOpenEnumA [MPR.@]
624 * See comments for WNetOpenEnumW.
626 DWORD WINAPI
WNetOpenEnumA( DWORD dwScope
, DWORD dwType
, DWORD dwUsage
,
627 LPNETRESOURCEA lpNet
, LPHANDLE lphEnum
)
631 TRACE( "(%08X, %08X, %08X, %p, %p)\n",
632 dwScope
, dwType
, dwUsage
, lpNet
, lphEnum
);
635 ret
= WN_BAD_POINTER
;
636 else if (!providerTable
|| providerTable
->numProviders
== 0)
642 LPNETRESOURCEW lpNetWide
= NULL
;
644 DWORD size
= sizeof(buf
), count
= 1;
645 BOOL allocated
= FALSE
;
647 ret
= _thunkNetResourceArrayAToW(lpNet
, &count
, buf
, &size
);
648 if (ret
== WN_MORE_DATA
)
650 lpNetWide
= HeapAlloc(GetProcessHeap(), 0,
654 ret
= _thunkNetResourceArrayAToW(lpNet
, &count
, lpNetWide
,
659 ret
= WN_OUT_OF_MEMORY
;
661 else if (ret
== WN_SUCCESS
)
662 lpNetWide
= (LPNETRESOURCEW
)buf
;
663 if (ret
== WN_SUCCESS
)
664 ret
= WNetOpenEnumW(dwScope
, dwType
, dwUsage
, lpNetWide
,
667 HeapFree(GetProcessHeap(), 0, lpNetWide
);
670 ret
= WNetOpenEnumW(dwScope
, dwType
, dwUsage
, NULL
, lphEnum
);
674 TRACE("Returning %d\n", ret
);
678 /*********************************************************************
679 * WNetOpenEnumW [MPR.@]
681 * Network enumeration has way too many parameters, so I'm not positive I got
682 * them right. What I've got so far:
684 * - If the scope is RESOURCE_GLOBALNET, and no LPNETRESOURCE is passed,
685 * all the network providers should be enumerated.
687 * - If the scope is RESOURCE_GLOBALNET, and LPNETRESOURCE is passed, and
688 * and neither the LPNETRESOURCE's lpRemoteName nor the LPNETRESOURCE's
689 * lpProvider is set, all the network providers should be enumerated.
690 * (This means the enumeration is a list of network providers, not that the
691 * enumeration is passed on to the providers.)
693 * - If the scope is RESOURCE_GLOBALNET, and LPNETRESOURCE is passed, and the
694 * resource matches the "Entire Network" resource (no remote name, no
695 * provider, comment is the "Entire Network" string), a RESOURCE_GLOBALNET
696 * enumeration is done on every network provider.
698 * - If the scope is RESOURCE_GLOBALNET, and LPNETRESOURCE is passed, and
699 * the LPNETRESOURCE's lpProvider is set, enumeration will be passed through
700 * only to the given network provider.
702 * - If the scope is RESOURCE_GLOBALNET, and LPNETRESOURCE is passed, and
703 * no lpProvider is set, enumeration will be tried on every network provider,
704 * in the order in which they're loaded.
706 * - The LPNETRESOURCE should be disregarded for scopes besides
707 * RESOURCE_GLOBALNET. MSDN states that lpNet must be NULL if dwScope is not
708 * RESOURCE_GLOBALNET, but Windows doesn't return an error if it isn't NULL.
710 * - If the scope is RESOURCE_CONTEXT, MS includes an "Entire Network" net
711 * resource in the enumerated list, as well as any machines in your
712 * workgroup. The machines in your workgroup come from doing a
713 * RESOURCE_CONTEXT enumeration of every Network Provider.
715 DWORD WINAPI
WNetOpenEnumW( DWORD dwScope
, DWORD dwType
, DWORD dwUsage
,
716 LPNETRESOURCEW lpNet
, LPHANDLE lphEnum
)
720 TRACE( "(%08X, %08X, %08X, %p, %p)\n",
721 dwScope
, dwType
, dwUsage
, lpNet
, lphEnum
);
724 ret
= WN_BAD_POINTER
;
725 else if (!providerTable
|| providerTable
->numProviders
== 0)
731 case RESOURCE_GLOBALNET
:
734 if (lpNet
->lpProvider
)
736 DWORD index
= _findProviderIndexW(lpNet
->lpProvider
);
738 if (index
!= BAD_PROVIDER_INDEX
)
740 if (providerTable
->table
[index
].openEnum
&&
741 providerTable
->table
[index
].dwEnumScopes
& WNNC_ENUM_GLOBAL
)
745 ret
= providerTable
->table
[index
].openEnum(
746 dwScope
, dwType
, dwUsage
, lpNet
, &handle
);
747 if (ret
== WN_SUCCESS
)
749 *lphEnum
= _createProviderEnumerator(
750 dwScope
, dwType
, dwUsage
, index
, handle
);
751 ret
= *lphEnum
? WN_SUCCESS
:
756 ret
= WN_NOT_SUPPORTED
;
759 ret
= WN_BAD_PROVIDER
;
761 else if (lpNet
->lpRemoteName
)
763 *lphEnum
= _createGlobalEnumeratorW(dwScope
,
764 dwType
, dwUsage
, lpNet
);
765 ret
= *lphEnum
? WN_SUCCESS
: WN_OUT_OF_MEMORY
;
769 if (lpNet
->lpComment
&& !strcmpW(lpNet
->lpComment
,
770 providerTable
->entireNetwork
))
772 /* comment matches the "Entire Network", enumerate
773 * global scope of every provider
775 *lphEnum
= _createGlobalEnumeratorW(dwScope
,
776 dwType
, dwUsage
, lpNet
);
780 /* this is the same as not having passed lpNet */
781 *lphEnum
= _createGlobalEnumeratorW(dwScope
,
782 dwType
, dwUsage
, NULL
);
784 ret
= *lphEnum
? WN_SUCCESS
: WN_OUT_OF_MEMORY
;
789 *lphEnum
= _createGlobalEnumeratorW(dwScope
, dwType
,
791 ret
= *lphEnum
? WN_SUCCESS
: WN_OUT_OF_MEMORY
;
794 case RESOURCE_CONTEXT
:
795 *lphEnum
= _createContextEnumerator(dwScope
, dwType
, dwUsage
);
796 ret
= *lphEnum
? WN_SUCCESS
: WN_OUT_OF_MEMORY
;
798 case RESOURCE_REMEMBERED
:
799 case RESOURCE_CONNECTED
:
800 *lphEnum
= _createNullEnumerator();
801 ret
= *lphEnum
? WN_SUCCESS
: WN_OUT_OF_MEMORY
;
804 WARN("unknown scope 0x%08x\n", dwScope
);
810 TRACE("Returning %d\n", ret
);
814 /*********************************************************************
815 * WNetEnumResourceA [MPR.@]
817 DWORD WINAPI
WNetEnumResourceA( HANDLE hEnum
, LPDWORD lpcCount
,
818 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
822 TRACE( "(%p, %p, %p, %p)\n", hEnum
, lpcCount
, lpBuffer
, lpBufferSize
);
825 ret
= WN_BAD_POINTER
;
827 ret
= WN_BAD_POINTER
;
829 ret
= WN_BAD_POINTER
;
830 else if (!lpBufferSize
)
831 ret
= WN_BAD_POINTER
;
832 else if (*lpBufferSize
< sizeof(NETRESOURCEA
))
834 *lpBufferSize
= sizeof(NETRESOURCEA
);
839 DWORD localCount
= *lpcCount
, localSize
= *lpBufferSize
;
840 LPVOID localBuffer
= HeapAlloc(GetProcessHeap(), 0, localSize
);
844 ret
= WNetEnumResourceW(hEnum
, &localCount
, localBuffer
,
846 if (ret
== WN_SUCCESS
|| (ret
== WN_MORE_DATA
&& localCount
!= -1))
848 /* FIXME: this isn't necessarily going to work in the case of
849 * WN_MORE_DATA, because our enumerator may have moved on to
850 * the next provider. MSDN states that a large (16KB) buffer
851 * size is the appropriate usage of this function, so
852 * hopefully it won't be an issue.
854 ret
= _thunkNetResourceArrayWToA(localBuffer
, &localCount
,
855 lpBuffer
, lpBufferSize
);
856 *lpcCount
= localCount
;
858 HeapFree(GetProcessHeap(), 0, localBuffer
);
861 ret
= WN_OUT_OF_MEMORY
;
865 TRACE("Returning %d\n", ret
);
869 static DWORD
_countProviderBytesW(PWNetProvider provider
)
875 ret
= sizeof(NETRESOURCEW
);
876 ret
+= 2 * (strlenW(provider
->name
) + 1) * sizeof(WCHAR
);
883 static DWORD
_enumerateProvidersW(PWNetEnumerator enumerator
, LPDWORD lpcCount
,
884 LPVOID lpBuffer
, const DWORD
*lpBufferSize
)
889 return WN_BAD_POINTER
;
890 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_GLOBAL
)
893 return WN_BAD_POINTER
;
895 return WN_BAD_POINTER
;
897 return WN_BAD_POINTER
;
898 if (*lpBufferSize
< sizeof(NETRESOURCEA
))
901 if (!providerTable
|| enumerator
->providerIndex
>=
902 providerTable
->numProviders
)
903 ret
= WN_NO_MORE_ENTRIES
;
906 DWORD bytes
= 0, count
= 0, countLimit
, i
;
907 LPNETRESOURCEW resource
;
910 countLimit
= *lpcCount
== -1 ?
911 providerTable
->numProviders
- enumerator
->providerIndex
: *lpcCount
;
912 while (count
< countLimit
&& bytes
< *lpBufferSize
)
914 DWORD bytesNext
= _countProviderBytesW(
915 &providerTable
->table
[count
+ enumerator
->providerIndex
]);
917 if (bytes
+ bytesNext
< *lpBufferSize
)
923 strNext
= (LPWSTR
)((LPBYTE
)lpBuffer
+ count
* sizeof(NETRESOURCEW
));
924 for (i
= 0, resource
= lpBuffer
; i
< count
; i
++, resource
++)
926 resource
->dwScope
= RESOURCE_GLOBALNET
;
927 resource
->dwType
= RESOURCETYPE_ANY
;
928 resource
->dwDisplayType
= RESOURCEDISPLAYTYPE_NETWORK
;
929 resource
->dwUsage
= RESOURCEUSAGE_CONTAINER
|
930 RESOURCEUSAGE_RESERVED
;
931 resource
->lpLocalName
= NULL
;
932 resource
->lpRemoteName
= strNext
;
933 strcpyW(resource
->lpRemoteName
,
934 providerTable
->table
[i
+ enumerator
->providerIndex
].name
);
935 strNext
+= strlenW(resource
->lpRemoteName
) + 1;
936 resource
->lpComment
= NULL
;
937 resource
->lpProvider
= strNext
;
938 strcpyW(resource
->lpProvider
,
939 providerTable
->table
[i
+ enumerator
->providerIndex
].name
);
940 strNext
+= strlenW(resource
->lpProvider
) + 1;
942 enumerator
->providerIndex
+= count
;
944 ret
= count
> 0 ? WN_SUCCESS
: WN_MORE_DATA
;
946 TRACE("Returning %d\n", ret
);
950 /* Advances the enumerator (assumed to be a global enumerator) to the next
951 * provider that supports the enumeration scope passed to WNetOpenEnum. Does
952 * not open a handle with the next provider.
953 * If the existing handle is NULL, may leave the enumerator unchanged, since
954 * the current provider may support the desired scope.
955 * If the existing handle is not NULL, closes it before moving on.
956 * Returns WN_SUCCESS on success, WN_NO_MORE_ENTRIES if there is no available
957 * provider, and another error on failure.
959 static DWORD
_globalEnumeratorAdvance(PWNetEnumerator enumerator
)
962 return WN_BAD_POINTER
;
963 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_GLOBAL
)
965 if (!providerTable
|| enumerator
->providerIndex
>=
966 providerTable
->numProviders
)
967 return WN_NO_MORE_ENTRIES
;
969 if (enumerator
->providerDone
)
972 enumerator
->providerDone
= FALSE
;
973 if (enumerator
->handle
)
975 providerTable
->table
[enumerator
->providerIndex
].closeEnum(
977 enumerator
->handle
= NULL
;
978 enumerator
->providerIndex
++;
980 if (enumerator
->dwScope
== RESOURCE_CONNECTED
)
981 dwEnum
= WNNC_ENUM_LOCAL
;
982 else if (enumerator
->dwScope
== RESOURCE_GLOBALNET
)
983 dwEnum
= WNNC_ENUM_GLOBAL
;
984 else if (enumerator
->dwScope
== RESOURCE_CONTEXT
)
985 dwEnum
= WNNC_ENUM_CONTEXT
;
986 for (; enumerator
->providerIndex
< providerTable
->numProviders
&&
987 !(providerTable
->table
[enumerator
->providerIndex
].dwEnumScopes
988 & dwEnum
); enumerator
->providerIndex
++)
991 return enumerator
->providerIndex
< providerTable
->numProviders
?
992 WN_SUCCESS
: WN_NO_MORE_ENTRIES
;
995 /* "Passes through" call to the next provider that supports the enumeration
997 * FIXME: if one call to a provider's enumerator succeeds while there's still
998 * space in lpBuffer, I don't call to the next provider. The caller may not
999 * expect that it should call EnumResourceW again with a return value of
1000 * WN_SUCCESS (depending what *lpcCount was to begin with). That means strings
1001 * may have to be moved around a bit, ick.
1003 static DWORD
_enumerateGlobalPassthroughW(PWNetEnumerator enumerator
,
1004 LPDWORD lpcCount
, LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1009 return WN_BAD_POINTER
;
1010 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_GLOBAL
)
1011 return WN_BAD_VALUE
;
1013 return WN_BAD_POINTER
;
1015 return WN_BAD_POINTER
;
1017 return WN_BAD_POINTER
;
1018 if (*lpBufferSize
< sizeof(NETRESOURCEW
))
1019 return WN_MORE_DATA
;
1021 ret
= _globalEnumeratorAdvance(enumerator
);
1022 if (ret
== WN_SUCCESS
)
1024 ret
= providerTable
->table
[enumerator
->providerIndex
].
1025 openEnum(enumerator
->dwScope
, enumerator
->dwType
,
1026 enumerator
->dwUsage
, enumerator
->lpNet
,
1027 &enumerator
->handle
);
1028 if (ret
== WN_SUCCESS
)
1030 ret
= providerTable
->table
[enumerator
->providerIndex
].
1031 enumResource(enumerator
->handle
, lpcCount
, lpBuffer
,
1033 if (ret
!= WN_MORE_DATA
)
1034 enumerator
->providerDone
= TRUE
;
1037 TRACE("Returning %d\n", ret
);
1041 static DWORD
_enumerateGlobalW(PWNetEnumerator enumerator
, LPDWORD lpcCount
,
1042 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1047 return WN_BAD_POINTER
;
1048 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_GLOBAL
)
1049 return WN_BAD_VALUE
;
1051 return WN_BAD_POINTER
;
1053 return WN_BAD_POINTER
;
1055 return WN_BAD_POINTER
;
1056 if (*lpBufferSize
< sizeof(NETRESOURCEW
))
1057 return WN_MORE_DATA
;
1059 return WN_NO_NETWORK
;
1061 switch (enumerator
->dwScope
)
1063 case RESOURCE_GLOBALNET
:
1064 if (enumerator
->lpNet
)
1065 ret
= _enumerateGlobalPassthroughW(enumerator
, lpcCount
,
1066 lpBuffer
, lpBufferSize
);
1068 ret
= _enumerateProvidersW(enumerator
, lpcCount
, lpBuffer
,
1071 case RESOURCE_CONTEXT
:
1072 ret
= _enumerateGlobalPassthroughW(enumerator
, lpcCount
, lpBuffer
,
1076 WARN("unexpected scope 0x%08x\n", enumerator
->dwScope
);
1077 ret
= WN_NO_MORE_ENTRIES
;
1079 TRACE("Returning %d\n", ret
);
1083 static DWORD
_enumerateProviderW(PWNetEnumerator enumerator
, LPDWORD lpcCount
,
1084 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1087 return WN_BAD_POINTER
;
1088 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_PROVIDER
)
1089 return WN_BAD_VALUE
;
1090 if (!enumerator
->handle
)
1091 return WN_BAD_VALUE
;
1093 return WN_BAD_POINTER
;
1095 return WN_BAD_POINTER
;
1097 return WN_BAD_POINTER
;
1099 return WN_NO_NETWORK
;
1100 if (enumerator
->providerIndex
>= providerTable
->numProviders
)
1101 return WN_NO_MORE_ENTRIES
;
1102 if (!providerTable
->table
[enumerator
->providerIndex
].enumResource
)
1103 return WN_BAD_VALUE
;
1104 return providerTable
->table
[enumerator
->providerIndex
].enumResource(
1105 enumerator
->handle
, lpcCount
, lpBuffer
, lpBufferSize
);
1108 static DWORD
_enumerateContextW(PWNetEnumerator enumerator
, LPDWORD lpcCount
,
1109 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1112 size_t cchEntireNetworkLen
, bytesNeeded
;
1115 return WN_BAD_POINTER
;
1116 if (enumerator
->enumType
!= WNET_ENUMERATOR_TYPE_CONTEXT
)
1117 return WN_BAD_VALUE
;
1119 return WN_BAD_POINTER
;
1121 return WN_BAD_POINTER
;
1123 return WN_BAD_POINTER
;
1125 return WN_NO_NETWORK
;
1127 cchEntireNetworkLen
= strlenW(providerTable
->entireNetwork
) + 1;
1128 bytesNeeded
= sizeof(NETRESOURCEW
) + cchEntireNetworkLen
* sizeof(WCHAR
);
1129 if (*lpBufferSize
< bytesNeeded
)
1131 *lpBufferSize
= bytesNeeded
;
1136 LPNETRESOURCEW lpNet
= lpBuffer
;
1138 lpNet
->dwScope
= RESOURCE_GLOBALNET
;
1139 lpNet
->dwType
= enumerator
->dwType
;
1140 lpNet
->dwDisplayType
= RESOURCEDISPLAYTYPE_ROOT
;
1141 lpNet
->dwUsage
= RESOURCEUSAGE_CONTAINER
;
1142 lpNet
->lpLocalName
= NULL
;
1143 lpNet
->lpRemoteName
= NULL
;
1144 lpNet
->lpProvider
= NULL
;
1145 /* odd, but correct: put comment at end of buffer, so it won't get
1146 * overwritten by subsequent calls to a provider's enumResource
1148 lpNet
->lpComment
= (LPWSTR
)((LPBYTE
)lpBuffer
+ *lpBufferSize
-
1149 (cchEntireNetworkLen
* sizeof(WCHAR
)));
1150 strcpyW(lpNet
->lpComment
, providerTable
->entireNetwork
);
1153 if (ret
== WN_SUCCESS
)
1155 DWORD bufferSize
= *lpBufferSize
- bytesNeeded
;
1157 /* "Entire Network" entry enumerated--morph this into a global
1158 * enumerator. enumerator->lpNet continues to be NULL, since it has
1159 * no meaning when the scope isn't RESOURCE_GLOBALNET.
1161 enumerator
->enumType
= WNET_ENUMERATOR_TYPE_GLOBAL
;
1162 ret
= _enumerateGlobalW(enumerator
, lpcCount
,
1163 (LPBYTE
)lpBuffer
+ bytesNeeded
, &bufferSize
);
1164 if (ret
== WN_SUCCESS
)
1166 /* reflect the fact that we already enumerated "Entire Network" */
1168 *lpBufferSize
= bufferSize
+ bytesNeeded
;
1172 /* the provider enumeration failed, but we already succeeded in
1173 * enumerating "Entire Network"--leave type as global to allow a
1174 * retry, but indicate success with a count of one.
1178 *lpBufferSize
= bytesNeeded
;
1181 TRACE("Returning %d\n", ret
);
1185 /*********************************************************************
1186 * WNetEnumResourceW [MPR.@]
1188 DWORD WINAPI
WNetEnumResourceW( HANDLE hEnum
, LPDWORD lpcCount
,
1189 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1193 TRACE( "(%p, %p, %p, %p)\n", hEnum
, lpcCount
, lpBuffer
, lpBufferSize
);
1196 ret
= WN_BAD_POINTER
;
1198 ret
= WN_BAD_POINTER
;
1200 ret
= WN_BAD_POINTER
;
1201 else if (!lpBufferSize
)
1202 ret
= WN_BAD_POINTER
;
1203 else if (*lpBufferSize
< sizeof(NETRESOURCEW
))
1205 *lpBufferSize
= sizeof(NETRESOURCEW
);
1210 PWNetEnumerator enumerator
= (PWNetEnumerator
)hEnum
;
1212 switch (enumerator
->enumType
)
1214 case WNET_ENUMERATOR_TYPE_NULL
:
1215 ret
= WN_NO_MORE_ENTRIES
;
1217 case WNET_ENUMERATOR_TYPE_GLOBAL
:
1218 ret
= _enumerateGlobalW(enumerator
, lpcCount
, lpBuffer
,
1221 case WNET_ENUMERATOR_TYPE_PROVIDER
:
1222 ret
= _enumerateProviderW(enumerator
, lpcCount
, lpBuffer
,
1225 case WNET_ENUMERATOR_TYPE_CONTEXT
:
1226 ret
= _enumerateContextW(enumerator
, lpcCount
, lpBuffer
,
1230 WARN("bogus enumerator type!\n");
1231 ret
= WN_NO_NETWORK
;
1236 TRACE("Returning %d\n", ret
);
1240 /*********************************************************************
1241 * WNetCloseEnum [MPR.@]
1243 DWORD WINAPI
WNetCloseEnum( HANDLE hEnum
)
1247 TRACE( "(%p)\n", hEnum
);
1251 PWNetEnumerator enumerator
= (PWNetEnumerator
)hEnum
;
1253 switch (enumerator
->enumType
)
1255 case WNET_ENUMERATOR_TYPE_NULL
:
1258 case WNET_ENUMERATOR_TYPE_GLOBAL
:
1259 if (enumerator
->lpNet
)
1260 _freeEnumNetResource(enumerator
->lpNet
);
1261 if (enumerator
->handle
)
1262 providerTable
->table
[enumerator
->providerIndex
].
1263 closeEnum(enumerator
->handle
);
1266 case WNET_ENUMERATOR_TYPE_PROVIDER
:
1267 if (enumerator
->handle
)
1268 providerTable
->table
[enumerator
->providerIndex
].
1269 closeEnum(enumerator
->handle
);
1273 WARN("bogus enumerator type!\n");
1274 ret
= WN_BAD_HANDLE
;
1276 HeapFree(GetProcessHeap(), 0, hEnum
);
1279 ret
= WN_BAD_HANDLE
;
1282 TRACE("Returning %d\n", ret
);
1286 /*********************************************************************
1287 * WNetGetResourceInformationA [MPR.@]
1289 * See WNetGetResourceInformationW
1291 DWORD WINAPI
WNetGetResourceInformationA( LPNETRESOURCEA lpNetResource
,
1292 LPVOID lpBuffer
, LPDWORD cbBuffer
,
1297 TRACE( "(%p, %p, %p, %p)\n",
1298 lpNetResource
, lpBuffer
, cbBuffer
, lplpSystem
);
1300 if (!providerTable
|| providerTable
->numProviders
== 0)
1301 ret
= WN_NO_NETWORK
;
1302 else if (lpNetResource
)
1304 LPNETRESOURCEW lpNetResourceW
= NULL
;
1305 DWORD size
= 1024, count
= 1;
1308 lpNetResourceW
= HeapAlloc(GetProcessHeap(), 0, size
);
1309 ret
= _thunkNetResourceArrayAToW(lpNetResource
, &count
, lpNetResourceW
, &size
);
1310 if (ret
== WN_MORE_DATA
)
1312 HeapFree(GetProcessHeap(), 0, lpNetResourceW
);
1313 lpNetResourceW
= HeapAlloc(GetProcessHeap(), 0, size
);
1315 ret
= _thunkNetResourceArrayAToW(lpNetResource
,
1316 &count
, lpNetResourceW
, &size
);
1318 ret
= WN_OUT_OF_MEMORY
;
1320 if (ret
== WN_SUCCESS
)
1322 LPWSTR lpSystemW
= NULL
;
1325 lpBufferW
= HeapAlloc(GetProcessHeap(), 0, size
);
1328 ret
= WNetGetResourceInformationW(lpNetResourceW
,
1329 lpBufferW
, &size
, &lpSystemW
);
1330 if (ret
== WN_MORE_DATA
)
1332 HeapFree(GetProcessHeap(), 0, lpBufferW
);
1333 lpBufferW
= HeapAlloc(GetProcessHeap(), 0, size
);
1335 ret
= WNetGetResourceInformationW(lpNetResourceW
,
1336 lpBufferW
, &size
, &lpSystemW
);
1338 ret
= WN_OUT_OF_MEMORY
;
1340 if (ret
== WN_SUCCESS
)
1342 ret
= _thunkNetResourceArrayWToA(lpBufferW
,
1343 &count
, lpBuffer
, cbBuffer
);
1344 HeapFree(GetProcessHeap(), 0, lpNetResourceW
);
1345 lpNetResourceW
= lpBufferW
;
1346 size
= sizeof(NETRESOURCEA
);
1347 size
+= WideCharToMultiByte(CP_ACP
, 0, lpNetResourceW
->lpRemoteName
,
1348 -1, NULL
, 0, NULL
, NULL
);
1349 size
+= WideCharToMultiByte(CP_ACP
, 0, lpNetResourceW
->lpProvider
,
1350 -1, NULL
, 0, NULL
, NULL
);
1352 len
= WideCharToMultiByte(CP_ACP
, 0, lpSystemW
,
1353 -1, NULL
, 0, NULL
, NULL
);
1354 if ((len
) && ( size
+ len
< *cbBuffer
))
1356 *lplpSystem
= (char*)lpBuffer
+ *cbBuffer
- len
;
1357 WideCharToMultiByte(CP_ACP
, 0, lpSystemW
, -1,
1358 *lplpSystem
, len
, NULL
, NULL
);
1365 ret
= WN_OUT_OF_MEMORY
;
1366 HeapFree(GetProcessHeap(), 0, lpBufferW
);
1369 ret
= WN_OUT_OF_MEMORY
;
1370 HeapFree(GetProcessHeap(), 0, lpSystemW
);
1372 HeapFree(GetProcessHeap(), 0, lpNetResourceW
);
1375 ret
= WN_NO_NETWORK
;
1379 TRACE("Returning %d\n", ret
);
1383 /*********************************************************************
1384 * WNetGetResourceInformationW [MPR.@]
1386 * WNetGetResourceInformationW function identifies the network provider
1387 * that owns the resource and gets information about the type of the resource.
1390 * lpNetResource [ I] the pointer to NETRESOURCEW structure, that
1391 * defines a network resource.
1392 * lpBuffer [ O] the pointer to buffer, containing result. It
1393 * contains NETRESOURCEW structure and strings to
1394 * which the members of the NETRESOURCEW structure
1396 * cbBuffer [I/O] the pointer to DWORD number - size of buffer
1398 * lplpSystem [ O] the pointer to string in the output buffer,
1399 * containing the part of the resource name without
1400 * names of the server and share.
1403 * NO_ERROR if the function succeeds. System error code if the function fails.
1406 DWORD WINAPI
WNetGetResourceInformationW( LPNETRESOURCEW lpNetResource
,
1407 LPVOID lpBuffer
, LPDWORD cbBuffer
,
1408 LPWSTR
*lplpSystem
)
1410 DWORD ret
= WN_NO_NETWORK
;
1413 TRACE( "(%p, %p, %p, %p)\n",
1414 lpNetResource
, lpBuffer
, cbBuffer
, lplpSystem
);
1417 ret
= WN_OUT_OF_MEMORY
;
1418 else if (providerTable
!= NULL
)
1420 /* FIXME: For function value of a variable is indifferent, it does
1421 * search of all providers in a network.
1423 for (index
= 0; index
< providerTable
->numProviders
; index
++)
1425 if(providerTable
->table
[index
].getCaps(WNNC_DIALOG
) &
1426 WNNC_DLG_GETRESOURCEINFORMATION
)
1428 if (providerTable
->table
[index
].getResourceInformation
)
1429 ret
= providerTable
->table
[index
].getResourceInformation(
1430 lpNetResource
, lpBuffer
, cbBuffer
, lplpSystem
);
1432 ret
= WN_NO_NETWORK
;
1433 if (ret
== WN_SUCCESS
)
1443 /*********************************************************************
1444 * WNetGetResourceParentA [MPR.@]
1446 DWORD WINAPI
WNetGetResourceParentA( LPNETRESOURCEA lpNetResource
,
1447 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1449 FIXME( "(%p, %p, %p): stub\n",
1450 lpNetResource
, lpBuffer
, lpBufferSize
);
1452 SetLastError(WN_NO_NETWORK
);
1453 return WN_NO_NETWORK
;
1456 /*********************************************************************
1457 * WNetGetResourceParentW [MPR.@]
1459 DWORD WINAPI
WNetGetResourceParentW( LPNETRESOURCEW lpNetResource
,
1460 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1462 FIXME( "(%p, %p, %p): stub\n",
1463 lpNetResource
, lpBuffer
, lpBufferSize
);
1465 SetLastError(WN_NO_NETWORK
);
1466 return WN_NO_NETWORK
;
1472 * Connection Functions
1475 /*********************************************************************
1476 * WNetAddConnectionA [MPR.@]
1478 DWORD WINAPI
WNetAddConnectionA( LPCSTR lpRemoteName
, LPCSTR lpPassword
,
1479 LPCSTR lpLocalName
)
1481 FIXME( "(%s, %p, %s): stub\n",
1482 debugstr_a(lpRemoteName
), lpPassword
, debugstr_a(lpLocalName
) );
1484 SetLastError(WN_NO_NETWORK
);
1485 return WN_NO_NETWORK
;
1488 /*********************************************************************
1489 * WNetAddConnectionW [MPR.@]
1491 DWORD WINAPI
WNetAddConnectionW( LPCWSTR lpRemoteName
, LPCWSTR lpPassword
,
1492 LPCWSTR lpLocalName
)
1494 FIXME( "(%s, %p, %s): stub\n",
1495 debugstr_w(lpRemoteName
), lpPassword
, debugstr_w(lpLocalName
) );
1497 SetLastError(WN_NO_NETWORK
);
1498 return WN_NO_NETWORK
;
1501 /*********************************************************************
1502 * WNetAddConnection2A [MPR.@]
1504 DWORD WINAPI
WNetAddConnection2A( LPNETRESOURCEA lpNetResource
,
1505 LPCSTR lpPassword
, LPCSTR lpUserID
,
1508 FIXME( "(%p, %p, %s, 0x%08X): stub\n",
1509 lpNetResource
, lpPassword
, debugstr_a(lpUserID
), dwFlags
);
1511 SetLastError(WN_NO_NETWORK
);
1512 return WN_NO_NETWORK
;
1515 /*********************************************************************
1516 * WNetAddConnection2W [MPR.@]
1518 DWORD WINAPI
WNetAddConnection2W( LPNETRESOURCEW lpNetResource
,
1519 LPCWSTR lpPassword
, LPCWSTR lpUserID
,
1522 FIXME( "(%p, %p, %s, 0x%08X): stub\n",
1523 lpNetResource
, lpPassword
, debugstr_w(lpUserID
), dwFlags
);
1525 SetLastError(WN_NO_NETWORK
);
1526 return WN_NO_NETWORK
;
1529 /*********************************************************************
1530 * WNetAddConnection3A [MPR.@]
1532 DWORD WINAPI
WNetAddConnection3A( HWND hwndOwner
, LPNETRESOURCEA lpNetResource
,
1533 LPCSTR lpPassword
, LPCSTR lpUserID
,
1536 FIXME( "(%p, %p, %p, %s, 0x%08X), stub\n",
1537 hwndOwner
, lpNetResource
, lpPassword
, debugstr_a(lpUserID
), dwFlags
);
1539 SetLastError(WN_NO_NETWORK
);
1540 return WN_NO_NETWORK
;
1543 /*********************************************************************
1544 * WNetAddConnection3W [MPR.@]
1546 DWORD WINAPI
WNetAddConnection3W( HWND hwndOwner
, LPNETRESOURCEW lpNetResource
,
1547 LPCWSTR lpPassword
, LPCWSTR lpUserID
,
1550 FIXME( "(%p, %p, %p, %s, 0x%08X), stub\n",
1551 hwndOwner
, lpNetResource
, lpPassword
, debugstr_w(lpUserID
), dwFlags
);
1553 SetLastError(WN_NO_NETWORK
);
1554 return WN_NO_NETWORK
;
1557 /*****************************************************************
1558 * WNetUseConnectionA [MPR.@]
1560 DWORD WINAPI
WNetUseConnectionA( HWND hwndOwner
, LPNETRESOURCEA lpNetResource
,
1561 LPCSTR lpPassword
, LPCSTR lpUserID
, DWORD dwFlags
,
1562 LPSTR lpAccessName
, LPDWORD lpBufferSize
,
1565 FIXME( "(%p, %p, %p, %s, 0x%08X, %s, %p, %p), stub\n",
1566 hwndOwner
, lpNetResource
, lpPassword
, debugstr_a(lpUserID
), dwFlags
,
1567 debugstr_a(lpAccessName
), lpBufferSize
, lpResult
);
1569 SetLastError(WN_NO_NETWORK
);
1570 return WN_NO_NETWORK
;
1573 /*****************************************************************
1574 * WNetUseConnectionW [MPR.@]
1576 DWORD WINAPI
WNetUseConnectionW( HWND hwndOwner
, LPNETRESOURCEW lpNetResource
,
1577 LPCWSTR lpPassword
, LPCWSTR lpUserID
, DWORD dwFlags
,
1578 LPWSTR lpAccessName
, LPDWORD lpBufferSize
,
1581 FIXME( "(%p, %p, %p, %s, 0x%08X, %s, %p, %p), stub\n",
1582 hwndOwner
, lpNetResource
, lpPassword
, debugstr_w(lpUserID
), dwFlags
,
1583 debugstr_w(lpAccessName
), lpBufferSize
, lpResult
);
1585 SetLastError(WN_NO_NETWORK
);
1586 return WN_NO_NETWORK
;
1589 /*********************************************************************
1590 * WNetCancelConnectionA [MPR.@]
1592 DWORD WINAPI
WNetCancelConnectionA( LPCSTR lpName
, BOOL fForce
)
1594 FIXME( "(%s, %d), stub\n", debugstr_a(lpName
), fForce
);
1599 /*********************************************************************
1600 * WNetCancelConnectionW [MPR.@]
1602 DWORD WINAPI
WNetCancelConnectionW( LPCWSTR lpName
, BOOL fForce
)
1604 FIXME( "(%s, %d), stub\n", debugstr_w(lpName
), fForce
);
1609 /*********************************************************************
1610 * WNetCancelConnection2A [MPR.@]
1612 DWORD WINAPI
WNetCancelConnection2A( LPCSTR lpName
, DWORD dwFlags
, BOOL fForce
)
1614 FIXME( "(%s, %08X, %d), stub\n", debugstr_a(lpName
), dwFlags
, fForce
);
1619 /*********************************************************************
1620 * WNetCancelConnection2W [MPR.@]
1622 DWORD WINAPI
WNetCancelConnection2W( LPCWSTR lpName
, DWORD dwFlags
, BOOL fForce
)
1624 FIXME( "(%s, %08X, %d), stub\n", debugstr_w(lpName
), dwFlags
, fForce
);
1629 /*****************************************************************
1630 * WNetRestoreConnectionA [MPR.@]
1632 DWORD WINAPI
WNetRestoreConnectionA( HWND hwndOwner
, LPCSTR lpszDevice
)
1634 FIXME( "(%p, %s), stub\n", hwndOwner
, debugstr_a(lpszDevice
) );
1636 SetLastError(WN_NO_NETWORK
);
1637 return WN_NO_NETWORK
;
1640 /*****************************************************************
1641 * WNetRestoreConnectionW [MPR.@]
1643 DWORD WINAPI
WNetRestoreConnectionW( HWND hwndOwner
, LPCWSTR lpszDevice
)
1645 FIXME( "(%p, %s), stub\n", hwndOwner
, debugstr_w(lpszDevice
) );
1647 SetLastError(WN_NO_NETWORK
);
1648 return WN_NO_NETWORK
;
1651 /**************************************************************************
1652 * WNetGetConnectionA [MPR.@]
1655 * - WN_BAD_LOCALNAME lpLocalName makes no sense
1656 * - WN_NOT_CONNECTED drive is a local drive
1657 * - WN_MORE_DATA buffer isn't big enough
1658 * - WN_SUCCESS success (net path in buffer)
1660 * FIXME: need to test return values under different errors
1662 DWORD WINAPI
WNetGetConnectionA( LPCSTR lpLocalName
,
1663 LPSTR lpRemoteName
, LPDWORD lpBufferSize
)
1668 ret
= WN_BAD_POINTER
;
1669 else if (!lpBufferSize
)
1670 ret
= WN_BAD_POINTER
;
1671 else if (!lpRemoteName
&& *lpBufferSize
)
1672 ret
= WN_BAD_POINTER
;
1675 int len
= MultiByteToWideChar(CP_ACP
, 0, lpLocalName
, -1, NULL
, 0);
1679 PWSTR wideLocalName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1683 WCHAR wideRemoteStatic
[MAX_PATH
];
1684 DWORD wideRemoteSize
= sizeof(wideRemoteStatic
) / sizeof(WCHAR
);
1686 MultiByteToWideChar(CP_ACP
, 0, lpLocalName
, -1, wideLocalName
, len
);
1688 /* try once without memory allocation */
1689 ret
= WNetGetConnectionW(wideLocalName
, wideRemoteStatic
,
1691 if (ret
== WN_SUCCESS
)
1693 int len
= WideCharToMultiByte(CP_ACP
, 0, wideRemoteStatic
,
1694 -1, NULL
, 0, NULL
, NULL
);
1696 if (len
<= *lpBufferSize
)
1698 WideCharToMultiByte(CP_ACP
, 0, wideRemoteStatic
, -1,
1699 lpRemoteName
, *lpBufferSize
, NULL
, NULL
);
1704 *lpBufferSize
= len
;
1708 else if (ret
== WN_MORE_DATA
)
1710 PWSTR wideRemote
= HeapAlloc(GetProcessHeap(), 0,
1711 wideRemoteSize
* sizeof(WCHAR
));
1715 ret
= WNetGetConnectionW(wideLocalName
, wideRemote
,
1717 if (ret
== WN_SUCCESS
)
1719 if (len
<= *lpBufferSize
)
1721 WideCharToMultiByte(CP_ACP
, 0, wideRemoteStatic
,
1722 -1, lpRemoteName
, *lpBufferSize
, NULL
, NULL
);
1727 *lpBufferSize
= len
;
1731 HeapFree(GetProcessHeap(), 0, wideRemote
);
1734 ret
= WN_OUT_OF_MEMORY
;
1736 HeapFree(GetProcessHeap(), 0, wideLocalName
);
1739 ret
= WN_OUT_OF_MEMORY
;
1742 ret
= WN_BAD_LOCALNAME
;
1746 TRACE("Returning %d\n", ret
);
1750 /**************************************************************************
1751 * WNetGetConnectionW [MPR.@]
1753 * FIXME: need to test return values under different errors
1755 DWORD WINAPI
WNetGetConnectionW( LPCWSTR lpLocalName
,
1756 LPWSTR lpRemoteName
, LPDWORD lpBufferSize
)
1760 TRACE("(%s, %p, %p)\n", debugstr_w(lpLocalName
), lpRemoteName
,
1764 ret
= WN_BAD_POINTER
;
1765 else if (!lpBufferSize
)
1766 ret
= WN_BAD_POINTER
;
1767 else if (!lpRemoteName
&& *lpBufferSize
)
1768 ret
= WN_BAD_POINTER
;
1769 else if (!lpLocalName
[0])
1770 ret
= WN_BAD_LOCALNAME
;
1773 if (lpLocalName
[1] == ':')
1775 switch(GetDriveTypeW(lpLocalName
))
1779 static const WCHAR unc
[] = { 'u','n','c','\\' };
1780 WCHAR rremote
[MAX_PATH
], *remote
= rremote
;
1781 if (!QueryDosDeviceW( lpLocalName
, remote
, MAX_PATH
)) remote
[0] = 0;
1782 else if (!strncmpW(remote
, unc
, 4))
1787 else if (remote
[0] != '\\' || remote
[1] != '\\')
1788 FIXME("Don't know how to convert %s to an unc\n", debugstr_w(remote
));
1790 if (strlenW(remote
) + 1 > *lpBufferSize
)
1792 *lpBufferSize
= strlenW(remote
) + 1;
1797 strcpyW( lpRemoteName
, remote
);
1798 *lpBufferSize
= strlenW(lpRemoteName
) + 1;
1803 case DRIVE_REMOVABLE
:
1806 TRACE("file is local\n");
1807 ret
= WN_NOT_CONNECTED
;
1810 ret
= WN_BAD_LOCALNAME
;
1814 ret
= WN_BAD_LOCALNAME
;
1818 TRACE("Returning %d\n", ret
);
1822 /**************************************************************************
1823 * WNetSetConnectionA [MPR.@]
1825 DWORD WINAPI
WNetSetConnectionA( LPCSTR lpName
, DWORD dwProperty
,
1828 FIXME( "(%s, %08X, %p): stub\n", debugstr_a(lpName
), dwProperty
, pvValue
);
1830 SetLastError(WN_NO_NETWORK
);
1831 return WN_NO_NETWORK
;
1834 /**************************************************************************
1835 * WNetSetConnectionW [MPR.@]
1837 DWORD WINAPI
WNetSetConnectionW( LPCWSTR lpName
, DWORD dwProperty
,
1840 FIXME( "(%s, %08X, %p): stub\n", debugstr_w(lpName
), dwProperty
, pvValue
);
1842 SetLastError(WN_NO_NETWORK
);
1843 return WN_NO_NETWORK
;
1846 /*****************************************************************
1847 * WNetGetUniversalNameA [MPR.@]
1849 DWORD WINAPI
WNetGetUniversalNameA ( LPCSTR lpLocalPath
, DWORD dwInfoLevel
,
1850 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1854 FIXME( "(%s, 0x%08X, %p, %p): stub\n",
1855 debugstr_a(lpLocalPath
), dwInfoLevel
, lpBuffer
, lpBufferSize
);
1857 switch (dwInfoLevel
)
1859 case UNIVERSAL_NAME_INFO_LEVEL
:
1861 LPUNIVERSAL_NAME_INFOA info
= lpBuffer
;
1863 size
= sizeof(*info
) + lstrlenA(lpLocalPath
) + 1;
1864 if (*lpBufferSize
< size
)
1869 info
->lpUniversalName
= (char *)info
+ sizeof(*info
);
1870 lstrcpyA(info
->lpUniversalName
, lpLocalPath
);
1871 *lpBufferSize
= size
;
1875 case REMOTE_NAME_INFO_LEVEL
:
1876 err
= WN_NO_NETWORK
;
1888 /*****************************************************************
1889 * WNetGetUniversalNameW [MPR.@]
1891 DWORD WINAPI
WNetGetUniversalNameW ( LPCWSTR lpLocalPath
, DWORD dwInfoLevel
,
1892 LPVOID lpBuffer
, LPDWORD lpBufferSize
)
1896 FIXME( "(%s, 0x%08X, %p, %p): stub\n",
1897 debugstr_w(lpLocalPath
), dwInfoLevel
, lpBuffer
, lpBufferSize
);
1899 switch (dwInfoLevel
)
1901 case UNIVERSAL_NAME_INFO_LEVEL
:
1903 LPUNIVERSAL_NAME_INFOW info
= lpBuffer
;
1905 size
= sizeof(*info
) + (lstrlenW(lpLocalPath
) + 1) * sizeof(WCHAR
);
1906 if (*lpBufferSize
< size
)
1911 info
->lpUniversalName
= (LPWSTR
)((char *)info
+ sizeof(*info
));
1912 lstrcpyW(info
->lpUniversalName
, lpLocalPath
);
1913 *lpBufferSize
= size
;
1917 case REMOTE_NAME_INFO_LEVEL
:
1918 err
= WN_NO_NETWORK
;
1936 /**************************************************************************
1937 * WNetGetUserA [MPR.@]
1939 * FIXME: we should not return ourselves, but the owner of the drive lpName
1941 DWORD WINAPI
WNetGetUserA( LPCSTR lpName
, LPSTR lpUserID
, LPDWORD lpBufferSize
)
1943 if (GetUserNameA( lpUserID
, lpBufferSize
)) return WN_SUCCESS
;
1944 return GetLastError();
1947 /*****************************************************************
1948 * WNetGetUserW [MPR.@]
1950 * FIXME: we should not return ourselves, but the owner of the drive lpName
1952 DWORD WINAPI
WNetGetUserW( LPCWSTR lpName
, LPWSTR lpUserID
, LPDWORD lpBufferSize
)
1954 if (GetUserNameW( lpUserID
, lpBufferSize
)) return WN_SUCCESS
;
1955 return GetLastError();
1958 /*********************************************************************
1959 * WNetConnectionDialog [MPR.@]
1961 DWORD WINAPI
WNetConnectionDialog( HWND hwnd
, DWORD dwType
)
1963 FIXME( "(%p, %08X): stub\n", hwnd
, dwType
);
1965 SetLastError(WN_NO_NETWORK
);
1966 return WN_NO_NETWORK
;
1969 /*********************************************************************
1970 * WNetConnectionDialog1A [MPR.@]
1972 DWORD WINAPI
WNetConnectionDialog1A( LPCONNECTDLGSTRUCTA lpConnDlgStruct
)
1974 FIXME( "(%p): stub\n", lpConnDlgStruct
);
1976 SetLastError(WN_NO_NETWORK
);
1977 return WN_NO_NETWORK
;
1980 /*********************************************************************
1981 * WNetConnectionDialog1W [MPR.@]
1983 DWORD WINAPI
WNetConnectionDialog1W( LPCONNECTDLGSTRUCTW lpConnDlgStruct
)
1985 FIXME( "(%p): stub\n", lpConnDlgStruct
);
1987 SetLastError(WN_NO_NETWORK
);
1988 return WN_NO_NETWORK
;
1991 /*********************************************************************
1992 * WNetDisconnectDialog [MPR.@]
1994 DWORD WINAPI
WNetDisconnectDialog( HWND hwnd
, DWORD dwType
)
1996 FIXME( "(%p, %08X): stub\n", hwnd
, dwType
);
1998 SetLastError(WN_NO_NETWORK
);
1999 return WN_NO_NETWORK
;
2002 /*********************************************************************
2003 * WNetDisconnectDialog1A [MPR.@]
2005 DWORD WINAPI
WNetDisconnectDialog1A( LPDISCDLGSTRUCTA lpConnDlgStruct
)
2007 FIXME( "(%p): stub\n", lpConnDlgStruct
);
2009 SetLastError(WN_NO_NETWORK
);
2010 return WN_NO_NETWORK
;
2013 /*********************************************************************
2014 * WNetDisconnectDialog1W [MPR.@]
2016 DWORD WINAPI
WNetDisconnectDialog1W( LPDISCDLGSTRUCTW lpConnDlgStruct
)
2018 FIXME( "(%p): stub\n", lpConnDlgStruct
);
2020 SetLastError(WN_NO_NETWORK
);
2021 return WN_NO_NETWORK
;
2024 /*********************************************************************
2025 * WNetGetLastErrorA [MPR.@]
2027 DWORD WINAPI
WNetGetLastErrorA( LPDWORD lpError
,
2028 LPSTR lpErrorBuf
, DWORD nErrorBufSize
,
2029 LPSTR lpNameBuf
, DWORD nNameBufSize
)
2031 FIXME( "(%p, %p, %d, %p, %d): stub\n",
2032 lpError
, lpErrorBuf
, nErrorBufSize
, lpNameBuf
, nNameBufSize
);
2034 SetLastError(WN_NO_NETWORK
);
2035 return WN_NO_NETWORK
;
2038 /*********************************************************************
2039 * WNetGetLastErrorW [MPR.@]
2041 DWORD WINAPI
WNetGetLastErrorW( LPDWORD lpError
,
2042 LPWSTR lpErrorBuf
, DWORD nErrorBufSize
,
2043 LPWSTR lpNameBuf
, DWORD nNameBufSize
)
2045 FIXME( "(%p, %p, %d, %p, %d): stub\n",
2046 lpError
, lpErrorBuf
, nErrorBufSize
, lpNameBuf
, nNameBufSize
);
2048 SetLastError(WN_NO_NETWORK
);
2049 return WN_NO_NETWORK
;
2052 /*********************************************************************
2053 * WNetGetNetworkInformationA [MPR.@]
2055 DWORD WINAPI
WNetGetNetworkInformationA( LPCSTR lpProvider
,
2056 LPNETINFOSTRUCT lpNetInfoStruct
)
2060 TRACE( "(%s, %p)\n", debugstr_a(lpProvider
), lpNetInfoStruct
);
2063 ret
= WN_BAD_POINTER
;
2068 len
= MultiByteToWideChar(CP_ACP
, 0, lpProvider
, -1, NULL
, 0);
2071 LPWSTR wideProvider
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2075 MultiByteToWideChar(CP_ACP
, 0, lpProvider
, -1, wideProvider
,
2077 ret
= WNetGetNetworkInformationW(wideProvider
, lpNetInfoStruct
);
2078 HeapFree(GetProcessHeap(), 0, wideProvider
);
2081 ret
= WN_OUT_OF_MEMORY
;
2084 ret
= GetLastError();
2088 TRACE("Returning %d\n", ret
);
2092 /*********************************************************************
2093 * WNetGetNetworkInformationW [MPR.@]
2095 DWORD WINAPI
WNetGetNetworkInformationW( LPCWSTR lpProvider
,
2096 LPNETINFOSTRUCT lpNetInfoStruct
)
2100 TRACE( "(%s, %p)\n", debugstr_w(lpProvider
), lpNetInfoStruct
);
2103 ret
= WN_BAD_POINTER
;
2104 else if (!lpNetInfoStruct
)
2105 ret
= WN_BAD_POINTER
;
2106 else if (lpNetInfoStruct
->cbStructure
< sizeof(NETINFOSTRUCT
))
2110 if (providerTable
&& providerTable
->numProviders
)
2112 DWORD providerIndex
= _findProviderIndexW(lpProvider
);
2114 if (providerIndex
!= BAD_PROVIDER_INDEX
)
2116 lpNetInfoStruct
->cbStructure
= sizeof(NETINFOSTRUCT
);
2117 lpNetInfoStruct
->dwProviderVersion
=
2118 providerTable
->table
[providerIndex
].dwSpecVersion
;
2119 lpNetInfoStruct
->dwStatus
= NO_ERROR
;
2120 lpNetInfoStruct
->dwCharacteristics
= 0;
2121 lpNetInfoStruct
->dwHandle
= 0;
2122 lpNetInfoStruct
->wNetType
=
2123 HIWORD(providerTable
->table
[providerIndex
].dwNetType
);
2124 lpNetInfoStruct
->dwPrinters
= -1;
2125 lpNetInfoStruct
->dwDrives
= -1;
2129 ret
= WN_BAD_PROVIDER
;
2132 ret
= WN_NO_NETWORK
;
2136 TRACE("Returning %d\n", ret
);
2140 /*****************************************************************
2141 * WNetGetProviderNameA [MPR.@]
2143 DWORD WINAPI
WNetGetProviderNameA( DWORD dwNetType
,
2144 LPSTR lpProvider
, LPDWORD lpBufferSize
)
2148 TRACE("(0x%08x, %s, %p)\n", dwNetType
, debugstr_a(lpProvider
),
2152 ret
= WN_BAD_POINTER
;
2153 else if (!lpBufferSize
)
2154 ret
= WN_BAD_POINTER
;
2161 ret
= WN_NO_NETWORK
;
2162 for (i
= 0; i
< providerTable
->numProviders
&&
2163 HIWORD(providerTable
->table
[i
].dwNetType
) != HIWORD(dwNetType
);
2166 if (i
< providerTable
->numProviders
)
2168 DWORD sizeNeeded
= WideCharToMultiByte(CP_ACP
, 0,
2169 providerTable
->table
[i
].name
, -1, NULL
, 0, NULL
, NULL
);
2171 if (*lpBufferSize
< sizeNeeded
)
2173 *lpBufferSize
= sizeNeeded
;
2178 WideCharToMultiByte(CP_ACP
, 0, providerTable
->table
[i
].name
,
2179 -1, lpProvider
, *lpBufferSize
, NULL
, NULL
);
2181 /* FIXME: is *lpBufferSize set to the number of characters
2187 ret
= WN_NO_NETWORK
;
2191 TRACE("Returning %d\n", ret
);
2195 /*****************************************************************
2196 * WNetGetProviderNameW [MPR.@]
2198 DWORD WINAPI
WNetGetProviderNameW( DWORD dwNetType
,
2199 LPWSTR lpProvider
, LPDWORD lpBufferSize
)
2203 TRACE("(0x%08x, %s, %p)\n", dwNetType
, debugstr_w(lpProvider
),
2207 ret
= WN_BAD_POINTER
;
2208 else if (!lpBufferSize
)
2209 ret
= WN_BAD_POINTER
;
2216 ret
= WN_NO_NETWORK
;
2217 for (i
= 0; i
< providerTable
->numProviders
&&
2218 HIWORD(providerTable
->table
[i
].dwNetType
) != HIWORD(dwNetType
);
2221 if (i
< providerTable
->numProviders
)
2223 DWORD sizeNeeded
= strlenW(providerTable
->table
[i
].name
) + 1;
2225 if (*lpBufferSize
< sizeNeeded
)
2227 *lpBufferSize
= sizeNeeded
;
2232 strcpyW(lpProvider
, providerTable
->table
[i
].name
);
2234 /* FIXME: is *lpBufferSize set to the number of characters
2240 ret
= WN_NO_NETWORK
;
2244 TRACE("Returning %d\n", ret
);