Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

To establish a network connection, the user must know something about the network to be connected to. At a minimum, the user must know the local name or UNC of the network. For more information about functions you can use to retrieve network data, see Retrieving Network Data. An application can use one of two functions to establish network connections: WNetAddConnection3and WNetConnectionDialog1. Network connections are not automatically restored in Windows Embedded CE when a user logs on.

If a user knows the data needed to identify the network resource, an application can call WNetAddConnection3. The following code example shows how WNetAddConnection3is used to establish a connection with a network resource described by a NETRESOURCEstructure.

Copy Code
DWORD dwResult;

// Make a connection to the network resource.
dwResult = WNetAddConnection3 (
				hwnd, 				 // Handle to the owner
window.
				&nr, 				// Retrieved from
enumeration.
				NULL, 				 // No password.
				NULL, 				 // Logged-in user.
				CONNECT_UPDATE_PROFILE);  // Update profile with
										// connection data.
if (dwResult == ERROR_ALREADY_ASSIGNED)
{
  MessageBox (hwnd, TEXT("Already connected to specified
resource."), 
			TEXT("Info"), MB_OK);
  return FALSE;
}

else if (dwResult == ERROR_DEVICE_ALREADY_REMEMBERED)
{
  MessageBox (hwnd, TEXT("Attempted reassignment of remembered
device"), 
			TEXT("Info"), MB_OK);
  return FALSE;
}
else if (dwResult != ERROR_SUCCESS)
{
  ErrorHandler (hwnd, dwResult, TEXT("WNetAddConnection3"));
  return FALSE;
}

MessageBox (hwnd, TEXT("Connected to specified resource."), 
			TEXT("Info"), MB_OK);

The WNetConnectionDialog1function creates a dialog box that enables a user to browse and connect to network resources. This function prompts the user to choose a local name or UNC in a dialog box. The following code example shows how WNetConnectionDialog1is called to create a dialog box that displays all disk resources on a network.

Copy Code
DWORD dwResult = WNetConnectionDialog1 (lpConnectDlgStruc);

if (dwResult != ERROR_SUCCESS)
{
  ErrorHandler (hwnd, dwResult, TEXT("WNetConnectionDialog1"));
  return FALSE;
}

See Also