[MPR]
[reactos.git] / reactos / dll / win32 / mpr / wnet.c
index 3e117e6..e634af7 100644 (file)
@@ -62,10 +62,11 @@ typedef struct _WNetProviderTable
     WNetProvider     table[1];
 } WNetProviderTable, *PWNetProviderTable;
 
-#define WNET_ENUMERATOR_TYPE_NULL     0
-#define WNET_ENUMERATOR_TYPE_GLOBAL   1
-#define WNET_ENUMERATOR_TYPE_PROVIDER 2
-#define WNET_ENUMERATOR_TYPE_CONTEXT  3
+#define WNET_ENUMERATOR_TYPE_NULL      0
+#define WNET_ENUMERATOR_TYPE_GLOBAL    1
+#define WNET_ENUMERATOR_TYPE_PROVIDER  2
+#define WNET_ENUMERATOR_TYPE_CONTEXT   3
+#define WNET_ENUMERATOR_TYPE_CONNECTED 4
 
 /* An WNet enumerator.  Note that the type doesn't correspond to the scope of
  * the enumeration; it represents one of the following types:
@@ -90,7 +91,7 @@ typedef struct _WNetEnumerator
     DWORD          dwScope;
     DWORD          dwType;
     DWORD          dwUsage;
-    LPNETRESOURCEW lpNet;
+    LPVOID         lpBuffer;
 } WNetEnumerator, *PWNetEnumerator;
 
 #define BAD_PROVIDER_INDEX (DWORD)0xffffffff
@@ -416,7 +417,7 @@ static PWNetEnumerator _createGlobalEnumeratorW(DWORD dwScope, DWORD dwType,
         ret->dwScope = dwScope;
         ret->dwType  = dwType;
         ret->dwUsage = dwUsage;
-        ret->lpNet   = _copyNetResourceForEnumW(lpNet);
+        ret->lpBuffer = _copyNetResourceForEnumW(lpNet);
     }
     return ret;
 }
@@ -460,6 +461,28 @@ static PWNetEnumerator _createContextEnumerator(DWORD dwScope, DWORD dwType,
     return ret;
 }
 
+static PWNetEnumerator _createConnectedEnumerator(DWORD dwScope, DWORD dwType,
+ DWORD dwUsage)
+{
+    PWNetEnumerator ret = HeapAlloc(GetProcessHeap(),
+     HEAP_ZERO_MEMORY, sizeof(WNetEnumerator));
+
+    if (ret)
+    {
+        ret->enumType = WNET_ENUMERATOR_TYPE_CONNECTED;
+        ret->dwScope = dwScope;
+        ret->dwType  = dwType;
+        ret->dwUsage = dwUsage;
+        ret->lpBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HANDLE) * providerTable->numProviders);
+        if (!ret->lpBuffer)
+        {
+            HeapFree(GetProcessHeap(), 0, ret);
+            ret = NULL;
+        }
+    }
+    return ret;
+}
+
 /* Thunks the array of wide-string LPNETRESOURCEs lpNetArrayIn into buffer
  * lpBuffer, with size *lpBufferSize.  lpNetArrayIn contains *lpcCount entries
  * to start.  On return, *lpcCount reflects the number thunked into lpBuffer.
@@ -821,10 +844,13 @@ DWORD WINAPI WNetOpenEnumW( DWORD dwScope, DWORD dwType, DWORD dwUsage,
                 ret = *lphEnum ? WN_SUCCESS : WN_OUT_OF_MEMORY;
                 break;
             case RESOURCE_REMEMBERED:
-            case RESOURCE_CONNECTED:
                 *lphEnum = _createNullEnumerator();
                 ret = *lphEnum ? WN_SUCCESS : WN_OUT_OF_MEMORY;
                 break;
+            case RESOURCE_CONNECTED:
+                *lphEnum = _createConnectedEnumerator(dwScope, dwType, dwUsage);
+                ret = *lphEnum ? WN_SUCCESS : WN_OUT_OF_MEMORY;
+                break;
             default:
                 WARN("unknown scope 0x%08x\n", dwScope);
                 ret = WN_BAD_VALUE;
@@ -1048,7 +1074,7 @@ static DWORD _enumerateGlobalPassthroughW(PWNetEnumerator enumerator,
     {
         ret = providerTable->table[enumerator->providerIndex].
          openEnum(enumerator->dwScope, enumerator->dwType,
-         enumerator->dwUsage, enumerator->lpNet,
+         enumerator->dwUsage, enumerator->lpBuffer,
          &enumerator->handle);
         if (ret == WN_SUCCESS)
         {
@@ -1086,7 +1112,7 @@ static DWORD _enumerateGlobalW(PWNetEnumerator enumerator, LPDWORD lpcCount,
     switch (enumerator->dwScope)
     {
         case RESOURCE_GLOBALNET:
-            if (enumerator->lpNet)
+            if (enumerator->lpBuffer)
                 ret = _enumerateGlobalPassthroughW(enumerator, lpcCount,
                  lpBuffer, lpBufferSize);
             else
@@ -1207,6 +1233,143 @@ static DWORD _enumerateContextW(PWNetEnumerator enumerator, LPDWORD lpcCount,
     return ret;
 }
 
+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;
+}
+
 /*********************************************************************
  * WNetEnumResourceW [MPR.@]
  */
@@ -1251,6 +1414,10 @@ DWORD WINAPI WNetEnumResourceW( HANDLE hEnum, LPDWORD lpcCount,
                 ret = _enumerateContextW(enumerator, lpcCount, lpBuffer,
                  lpBufferSize);
                 break;
+            case WNET_ENUMERATOR_TYPE_CONNECTED:
+                ret = _enumerateConnectedW(enumerator, lpcCount, lpBuffer,
+                 lpBufferSize);
+                break;
             default:
                 WARN("bogus enumerator type!\n");
                 ret = WN_NO_NETWORK;
@@ -1267,7 +1434,8 @@ DWORD WINAPI WNetEnumResourceW( HANDLE hEnum, LPDWORD lpcCount,
  */
 DWORD WINAPI WNetCloseEnum( HANDLE hEnum )
 {
-    DWORD ret;
+    DWORD ret, index;
+    PHANDLE handles;
 
     TRACE( "(%p)\n", hEnum );
 
@@ -1277,12 +1445,22 @@ DWORD WINAPI WNetCloseEnum( HANDLE hEnum )
 
         switch (enumerator->enumType)
         {
+            case WNET_ENUMERATOR_TYPE_CONNECTED:
+                handles = enumerator->lpBuffer;
+                for (index = 0; index < providerTable->numProviders; index++)
+                {
+                    if (providerTable->table[index].dwEnumScopes && handles[index] != 0)
+                        providerTable->table[index].closeEnum(handles[index]);
+                }
+                HeapFree(GetProcessHeap(), 0, handles);
+                ret = WN_SUCCESS;
+                break;
             case WNET_ENUMERATOR_TYPE_NULL:
                 ret = WN_SUCCESS;
                 break;
             case WNET_ENUMERATOR_TYPE_GLOBAL:
-                if (enumerator->lpNet)
-                    _freeEnumNetResource(enumerator->lpNet);
+                if (enumerator->lpBuffer)
+                    _freeEnumNetResource(enumerator->lpBuffer);
                 if (enumerator->handle)
                     providerTable->table[enumerator->providerIndex].
                      closeEnum(enumerator->handle);
@@ -1580,18 +1758,18 @@ struct use_connection_context
     void *accessname;
     DWORD *buffer_size;
     DWORD *result;
-    DWORD (*pre_set_accessname)(struct use_connection_context*);
-    void  (*set_accessname)(struct use_connection_context*);
+    DWORD (*pre_set_accessname)(struct use_connection_context*, WCHAR *);
+    void  (*set_accessname)(struct use_connection_context*, WCHAR *);
 };
 
-static DWORD use_connection_pre_set_accessnameW(struct use_connection_context *ctxt)
+static DWORD use_connection_pre_set_accessnameW(struct use_connection_context *ctxt, WCHAR *local_name)
 {
     if (ctxt->accessname && ctxt->buffer_size && *ctxt->buffer_size)
     {
         DWORD len;
 
-        if (ctxt->resource->lpLocalName)
-            len = strlenW(ctxt->resource->lpLocalName);
+        if (local_name)
+            len = strlenW(local_name);
         else
             len = strlenW(ctxt->resource->lpRemoteName);
 
@@ -1607,149 +1785,101 @@ static DWORD use_connection_pre_set_accessnameW(struct use_connection_context *c
     return ERROR_SUCCESS;
 }
 
-static void use_connection_set_accessnameW(struct use_connection_context *ctxt)
+static void use_connection_set_accessnameW(struct use_connection_context *ctxt, WCHAR *local_name)
 {
     WCHAR *accessname = ctxt->accessname;
-    if (ctxt->resource->lpLocalName)
-        strcpyW(accessname, ctxt->resource->lpLocalName);
+    if (local_name)
+    {
+        strcpyW(accessname, local_name);
+        if (ctxt->result)
+            *ctxt->result = CONNECT_LOCALDRIVE;
+    }
     else
         strcpyW(accessname, ctxt->resource->lpRemoteName);
 }
 
-static WCHAR * select_provider(struct use_connection_context *ctxt)
+static DWORD wnet_use_provider( struct use_connection_context *ctxt, NETRESOURCEW * netres, WNetProvider *provider, BOOLEAN redirect )
 {
-    DWORD ret, prov_size = 0x1000, len;
-    LPNETRESOURCEW provider;
-    WCHAR * system;
-
-    provider = HeapAlloc(GetProcessHeap(), 0, prov_size);
-    if (!provider)
-    {
-        return NULL;
-    }
+    DWORD caps, ret;
 
-    ret = WNetGetResourceInformationW(ctxt->resource, provider, &prov_size, &system);
-    if (ret == ERROR_MORE_DATA)
-    {
-        HeapFree(GetProcessHeap(), 0, provider);
-        provider = HeapAlloc(GetProcessHeap(), 0, prov_size);
-        if (!provider)
-        {
-            return NULL;
-        }
-
-        ret = WNetGetResourceInformationW(ctxt->resource, provider, &prov_size, &system);
-    }
+    caps = provider->getCaps(WNNC_CONNECTION);
+    if (!(caps & (WNNC_CON_ADDCONNECTION | WNNC_CON_ADDCONNECTION3)))
+        return ERROR_BAD_PROVIDER;
 
-    if (ret != NO_ERROR)
+    ret = WN_ACCESS_DENIED;
+    do
     {
-        HeapFree(GetProcessHeap(), 0, provider);
-        return NULL;
-    }
+        if ((caps & WNNC_CON_ADDCONNECTION3) && provider->addConnection3)
+            ret = provider->addConnection3(ctxt->hwndOwner, netres, ctxt->password, ctxt->userid, ctxt->flags);
+        else if ((caps & WNNC_CON_ADDCONNECTION) && provider->addConnection)
+            ret = provider->addConnection(netres, ctxt->password, ctxt->userid);
 
-    len = WideCharToMultiByte(CP_ACP, 0, provider->lpProvider, -1, NULL, 0, NULL, NULL);
-    ctxt->resource->lpProvider = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
-    if (ctxt->resource->lpProvider)
-        memcpy(ctxt->resource->lpProvider, provider->lpProvider, len * sizeof(WCHAR));
+        if (ret == WN_ALREADY_CONNECTED && redirect)
+            netres->lpLocalName[0] -= 1;
+    } while (redirect && ret == WN_ALREADY_CONNECTED && netres->lpLocalName[0] >= 'C');
 
-    HeapFree(GetProcessHeap(), 0, provider);
+    if (ret == WN_SUCCESS && ctxt->accessname)
+        ctxt->set_accessname(ctxt, netres->lpLocalName);
 
-    return ctxt->resource->lpProvider;
+    return ret;
 }
 
 static DWORD wnet_use_connection( struct use_connection_context *ctxt )
 {
     WNetProvider *provider;
-    DWORD index, ret, caps;
-    BOOLEAN redirect = FALSE, prov = FALSE;
-    WCHAR letter[3] = {'z', ':', 0};
+    DWORD index, ret = WN_NO_NETWORK;
+    BOOL redirect = FALSE;
+    WCHAR letter[3] = {'Z', ':', 0};
+    NETRESOURCEW netres;
 
     if (!providerTable || providerTable->numProviders == 0)
         return WN_NO_NETWORK;
 
     if (!ctxt->resource)
         return ERROR_INVALID_PARAMETER;
+    netres = *ctxt->resource;
 
-    if (!ctxt->resource->lpLocalName && (ctxt->flags & CONNECT_REDIRECT))
+    if (!netres.lpLocalName && (ctxt->flags & CONNECT_REDIRECT))
     {
-        if (ctxt->resource->dwType != RESOURCETYPE_DISK && ctxt->resource->dwType != RESOURCETYPE_PRINT)
-        {
+        if (netres.dwType != RESOURCETYPE_DISK && netres.dwType != RESOURCETYPE_PRINT)
             return ERROR_BAD_DEV_TYPE;
-        }
 
-        if (ctxt->resource->dwType == RESOURCETYPE_PRINT)
+        if (netres.dwType == RESOURCETYPE_PRINT)
         {
-            FIXME("Locale device selection is not implemented for printers.\n");
+            FIXME("Local device selection is not implemented for printers.\n");
             return WN_NO_NETWORK;
         }
 
         redirect = TRUE;
-        ctxt->resource->lpLocalName = letter;
+        netres.lpLocalName = letter;
     }
 
     if (ctxt->flags & CONNECT_INTERACTIVE)
-    {
-        ret = ERROR_BAD_NET_NAME;
-        goto done;
-    }
-
-    if (!ctxt->resource->lpProvider)
-    {
-        ctxt->resource->lpProvider = select_provider(ctxt);
-        if (!ctxt->resource->lpProvider)
-        {
-            ret = ERROR_NO_NET_OR_BAD_PATH;
-            goto done;
-        }
+        return ERROR_BAD_NET_NAME;
 
-        prov = TRUE;
-    }
-
-    index = _findProviderIndexW(ctxt->resource->lpProvider);
-    if (index == BAD_PROVIDER_INDEX)
-    {
-        ret = ERROR_BAD_PROVIDER;
-        goto done;
-    }
+    if ((ret = ctxt->pre_set_accessname(ctxt, netres.lpLocalName)))
+        return ret;
 
-    provider = &providerTable->table[index];
-    caps = provider->getCaps(WNNC_CONNECTION);
-    if (!(caps & (WNNC_CON_ADDCONNECTION | WNNC_CON_ADDCONNECTION3)))
+    if (netres.lpProvider)
     {
-        ret = ERROR_BAD_PROVIDER;
-        goto done;
-    }
+        index = _findProviderIndexW(netres.lpProvider);
+        if (index == BAD_PROVIDER_INDEX)
+            return ERROR_BAD_PROVIDER;
 
-    if ((ret = ctxt->pre_set_accessname(ctxt)))
-    {
-        goto done;
+        provider = &providerTable->table[index];
+        ret = wnet_use_provider(ctxt, &netres, provider, redirect);
     }
-
-    ret = WN_ACCESS_DENIED;
-    do
-    {
-        if ((caps & WNNC_CON_ADDCONNECTION3) && provider->addConnection3)
-            ret = provider->addConnection3(ctxt->hwndOwner, ctxt->resource, ctxt->password, ctxt->userid, ctxt->flags);
-        else if ((caps & WNNC_CON_ADDCONNECTION) && provider->addConnection)
-            ret = provider->addConnection(ctxt->resource, ctxt->password, ctxt->userid);
-
-        if (redirect)
-            letter[0] -= 1;
-    } while (redirect && ret == WN_ALREADY_CONNECTED && letter[0] >= 'c');
-
-    if (ret == WN_SUCCESS && ctxt->accessname)
-        ctxt->set_accessname(ctxt);
-
-done:
-    if (prov)
+    else
     {
-        HeapFree(GetProcessHeap(), 0, ctxt->resource->lpProvider);
-        ctxt->resource->lpProvider = NULL;
+        for (index = 0; index < providerTable->numProviders; index++)
+        {
+            provider = &providerTable->table[index];
+            ret = wnet_use_provider(ctxt, &netres, provider, redirect);
+            if (ret == WN_SUCCESS || ret == WN_ALREADY_CONNECTED)
+                break;
+        }
     }
 
-    if (redirect)
-        ctxt->resource->lpLocalName = NULL;
-
     return ret;
 }
 
@@ -1780,14 +1910,14 @@ DWORD WINAPI WNetUseConnectionW( HWND hwndOwner, NETRESOURCEW *resource, LPCWSTR
     return wnet_use_connection(&ctxt);
 }
 
-static DWORD use_connection_pre_set_accessnameA(struct use_connection_context *ctxt)
+static DWORD use_connection_pre_set_accessnameA(struct use_connection_context *ctxt, WCHAR *local_name)
 {
     if (ctxt->accessname && ctxt->buffer_size && *ctxt->buffer_size)
     {
         DWORD len;
 
-        if (ctxt->resourceA->lpLocalName)
-            len = strlen(ctxt->resourceA->lpLocalName);
+        if (local_name)
+            len = WideCharToMultiByte(CP_ACP, 0, local_name, -1, NULL, 0, NULL, NULL) - 1;
         else
             len = strlen(ctxt->resourceA->lpRemoteName);
 
@@ -1803,11 +1933,15 @@ static DWORD use_connection_pre_set_accessnameA(struct use_connection_context *c
     return ERROR_SUCCESS;
 }
 
-static void use_connection_set_accessnameA(struct use_connection_context *ctxt)
+static void use_connection_set_accessnameA(struct use_connection_context *ctxt, WCHAR *local_name)
 {
     char *accessname = ctxt->accessname;
-    if (ctxt->resourceA->lpLocalName)
-        strcpy(accessname, ctxt->resourceA->lpLocalName);
+    if (local_name)
+    {
+        WideCharToMultiByte(CP_ACP, 0, local_name, -1, accessname, *ctxt->buffer_size, NULL, NULL);
+        if (ctxt->result)
+            *ctxt->result = CONNECT_LOCALDRIVE;
+    }
     else
         strcpy(accessname, ctxt->resourceA->lpRemoteName);
 }
@@ -1886,9 +2020,7 @@ DWORD WINAPI WNetUseConnectionA( HWND hwndOwner, NETRESOURCEA *resource,
  */
 DWORD WINAPI WNetCancelConnectionA( LPCSTR lpName, BOOL fForce )
 {
-    FIXME( "(%s, %d), stub\n", debugstr_a(lpName), fForce );
-
-    return WN_SUCCESS;
+    return WNetCancelConnection2A(lpName, 0, fForce);
 }
 
 /*********************************************************************
@@ -1896,9 +2028,7 @@ DWORD WINAPI WNetCancelConnectionA( LPCSTR lpName, BOOL fForce )
  */
 DWORD WINAPI WNetCancelConnectionW( LPCWSTR lpName, BOOL fForce )
 {
-    FIXME( "(%s, %d), stub\n", debugstr_w(lpName), fForce );
-
-    return WN_SUCCESS;
+    return WNetCancelConnection2W(lpName, 0, fForce);
 }
 
 /*********************************************************************
@@ -1906,9 +2036,15 @@ DWORD WINAPI WNetCancelConnectionW( LPCWSTR lpName, BOOL fForce )
  */
 DWORD WINAPI WNetCancelConnection2A( LPCSTR lpName, DWORD dwFlags, BOOL fForce )
 {
-    FIXME( "(%s, %08X, %d), stub\n", debugstr_a(lpName), dwFlags, fForce );
+    DWORD ret;
+    WCHAR * name = strdupAtoW(lpName);
+    if (!name)
+        return ERROR_NOT_CONNECTED;
+
+    ret = WNetCancelConnection2W(name, dwFlags, fForce);
+    HeapFree(GetProcessHeap(), 0, name);
 
-    return WN_SUCCESS;
+    return ret;
 }
 
 /*********************************************************************
@@ -1924,7 +2060,7 @@ DWORD WINAPI WNetCancelConnection2W( LPCWSTR lpName, DWORD dwFlags, BOOL fForce
         for (index = 0; index < providerTable->numProviders; index++)
         {
             if(providerTable->table[index].getCaps(WNNC_CONNECTION) &
-                WNNC_CON_GETCONNECTIONS)
+                WNNC_CON_CANCELCONNECTION)
             {
                 if (providerTable->table[index].cancelConnection)
                     ret = providerTable->table[index].cancelConnection((LPWSTR)lpName, fForce);