开发过程中的记录,Mark一下吧!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
void CTestDlg::OnButtonMapping() { // TODO: Add your control notification handler code here UpdateData( TRUE ); if( m_dir.IsEmpty() ) { AfxMessageBox("请输入要映射的网络文件夹"); return; } if( m_driver.IsEmpty() ) { AfxMessageBox("请输入映射后的驱动器号"); return; } NETRESOURCE net; net.dwScope = RESOURCE_GLOBALNET; net.dwType = RESOURCETYPE_DISK; net.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE; net.dwUsage = RESOURCEUSAGE_CONNECTABLE; net.lpLocalName = m_driver.GetBuffer( 0 ); net.lpRemoteName = m_dir.GetBuffer( 0 ); net.lpComment = NULL; net.lpProvider = NULL; DWORD Derr; Derr = WNetAddConnection2(&net, "123", "user01", CONNECT_UPDATE_PROFILE); if( Derr == NO_ERROR ) { AfxMessageBox("映射网络驱动器成功!"); DeleteFile("Z:\\test_xx.txt"); //删除一个文件,试试 } else { AfxMessageBox("映射网络驱动器失败!"); } m_driver.ReleaseBuffer(); m_dir.ReleaseBuffer(); } |
WNetCancelConnection2(m_driver,0,false); //这个是取消映射的驱动器。