要取消与网络资源的连接,应用程序可以调用WNetCancelConnection2功能,如以下示例所示。
DWORD dwResult;
dwResult = WNetCancelConnection2("z:",
CONNECT_UPDATE_PROFILE, //从配置文件中删除连接
FALSE); //如果打开的文件或作业失败
if (dwResult == ERROR_NOT_CONNECTED)
{
TextOut(hdc, 10, 10, "Drive z: not connected.", 23);
return FALSE;
}
else if(dwResult != NO_ERROR)
{
//应用程序定义的错误处理程序在
//标题为“Retrieving Network Errors”的部分。
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetCancelConnection2");
return FALSE;
}
TextOut(hdc, 10, 10, "Connection closed for z:.", 25);
支持WNetCancelConnection功能与早期版本的Windows for Workgroups兼容。对于新的应用程序,请使用WNetCancelConnection2.