分类: WINDOWS
2005-10-17 16:00:37
第八节: 结束一网络连接
结束一网络资源的连接可用函数WNetCancelConnection2 .
DWORD dwResult;
dwResult = WNetCancelConnection2("z:",
CONNECT_UPDATE_PROFILE, // 从PROFILE中删除连接
FALSE); //
if (dwResult == ERROR_NOT_CONNECTED)
{
TextOut(hdc, 10, 10, "驱动器 z: 没有连接.", 23);
return FALSE;
}
else if(dwResult != NO_ERROR)
{
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetCancelConnection2");
return FALSE;
}
TextOut(hdc, 10, 10, "连接被关闭 驱动器z:.", 25);
;====汇编语言描述(BY 谢小荣)=====
AsmCancelWNetConnection PROTO :DWORD,:DWORD
.data
msg_cancelwnet_2 db "此驱动器没有连接.",0
msg_cancelwnet_1 db "此驱动器连接被关闭 .",0
msg_cancelwnet_3 db "错误的连接脚本",0
msg_cancelwnet_4 db "驱动器设备正在由一活动进程使用,不能断开连接",0
msg_cancelwnet_5 db "不能打开连接脚本文件来处理持久连接",0
msg_cancelwnet_6 db "其他错误",0
.data?
dwResult dd ?
.code
;=====在调用此例程时hdc可换成返回成功或错误的参数指针
AsmCancelWNetConnection proc hwnd:DWORD,hdc:DWORD ;hwnd是窗口句柄,hdc是DC句柄
invoke WNetCancelConnection2,addr drvname,CONNECT_UPDATE_PROFILE,FALSE
.IF EAX==NO_ERROR
invoke TextOut,hdc,10,10,addr msg_cancelwnet_1,25
MOV EAX,0 ;调用过程读返回码可知道是否成功
.ELSE
.IF EAX==ERROR_NOT_CONNECTED
invoke TextOut,hdc,10,10,addr msg_cancelwnet_2,23
.ELSEIF EAX==ERROR_BAD_PROFILE
invoke TextOut,hdc,10,10,addr msg_cancelwnet_3,23
.ELSEIF EAX==ERROR_DEVICE_IN_USE
invoke TextOut,hdc,10,10,addr msg_cancelwnet_4,50
.ELSEIF EAX==ERROR_CANNOT_OPEN_PROFILE
invoke TextOut,hdc,10,10,addr msg_cancelwnet_5,46
.ELSE
invoke TextOut,hdc,10,10,addr msg_cancelwnet_6,14
.ENDIF
MOV EAX,1
.ENDIF
RET
AsmCancelWNetConnection endp