16.2.4 Retrieving the Connection Name

To retrieve the name of the network resource that is associated with a local device, an application can use the WNetGetConnection function, as shown in the following code fragment:

CHAR achDeviceName[80];

DWORD dwResult, cchBuff = sizeof(achDeviceName);

dwResult = WNetGetConnection("z:",

(LPSTR) achDeviceName,

&cchBuff);

switch (dwResult) {

case NO_ERROR:

TextOut(hdc, 10, 10, (LPSTR) achDeviceName,

lstrlen((LPSTR) achDeviceName));

break;

case ERROR_NOT_CONNECTED:

TextOut(hdc, 10, 10, "Device z: not connected.", 24);

case ERROR_CONNECTION_UNAVAIL:

TextOut(hdc, 10, 10, "Connection unavailable.", 23);

default:

ErrorHandler(hwnd, dwResult, "WNetGetConnection");

return FALSE;

}