Windows NT Only
To retrieve the name of the network resource associated with a local device, an application can use the WNetGetConnection function, as shown in the following example.
CHAR szDeviceName[80];
DWORD dwResult, cchBuff = sizeof(szDeviceName);
dwResult = WNetGetConnection("z:",
(LPSTR) szDeviceName,
&cchBuff);
switch (dwResult)
{
case NO_ERROR:
TextOut(hdc, 10, 10, (LPSTR) szDeviceName,
lstrlen((LPSTR) szDeviceName));
break;
case ERROR_NOT_CONNECTED:
TextOut(hdc, 10, 10, "Device z: not connected.", 24);
case ERROR_CONNECTION_UNAVAIL:
// A connection is remembered but not connected.
TextOut(hdc, 10, 10, "Connection unavailable.", 23);
default:
// An application-defined error handler is demonstrated in the
// section titled "Retrieving Network Errors."
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetGetConnection");
return FALSE;
}