Compartilhar via


Retrieving a Connection Name

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

WNet provides two functions for retrieving a connection name: WNetGetUniversalName and WNetGetConnection. WNetGetUniversalName takes a drive-based path for a network connection and obtains a more universal name in the form of a data structure.

WNetGetConnection enables an application to retrieve the name of a network resource associated with a local device. The following code example shows how WNetGetConnection retrieves the network name of a local device called MyDevice.

TCHAR szDeviceName[80];
DWORD dwResult, 
      cchBuffer = sizeof (szDeviceName);

dwResult = WNetGetConnection (TEXT("MyDevice"), szDeviceName, 
                              &cchBuffer);
switch (dwResult) 
{
  case ERROR_SUCCESS:
    MessageBox (hwnd, szDeviceName, TEXT("Info"), MB_OK);
    break;

  case ERROR_NOT_CONNECTED:
    MessageBox (hwnd, TEXT("MyDevice is not connected."), 
                TEXT("Info"), MB_OK);
    break;

  case ERROR_CONNECTION_UNAVAIL:
    // A connection is remembered, but not connected. 
    MessageBox (hwnd, TEXT("Connection unavailable."), 
                TEXT("Info"), MB_OK);
    break;

  default:
    ErrorHandler (hwnd, dwResult, TEXT("WNetGetConnection"));
    break;
} 

See Also

Concepts

Windows Networking API/Redirector Application Development
Managing Network Connections with WNet
Retrieving Network Data