www.pudn.com > NetHostEnumÁоÙ.rar > Network.h
///////////////////////////////////////////////////////////////////////////// // Copyright (C) 1997 by Joerg Koenig and the ADG mbH, Mannheim, Germany // All rights reserved // // Distribute freely, except: don't remove my name from the source or // documentation (don't take credit for my work), mark your changes (don't // get me blamed for your possible bugs), don't alter or remove this // notice. // No warrantee of any kind, express or implied, is included with this // software; use at your own risk, responsibility for damages (if any) to // anyone resulting from the use of this software rests entirely with the // user. // // Send bug reports, bug fixes, enhancements, requests, flames, etc., and // I'll try to keep a version up to date. I can be reached as follows: // J.Koenig@adg.de (company site) // Joerg.Koenig@rhein-neckar.de (private site) ///////////////////////////////////////////////////////////////////////////// // last revised $Date: 3.02.98 20:27 $ #ifndef Network_h #define Network_h #include#pragma message("network library is linking with \"mpr.lib\"") #pragma comment(lib, "mpr.lib") class CNetwork { LPTSTR m_pszError ; public: // constants #define _BIT(n) (1< (if this // member is NULL or empty). // can be set to "CONNECT_UPDATE_PROFILE" to make the // connection persistent (i.e. reconnect when the user logs on). // if is NULL, it defaults to the current user. // if is NULL, it defaults to the 's password. // This function calls NetError() (see below) and returns FALSE // if the connection fails; TRUE on success. // See WNetAddConnection2() in the online-help for more details BOOL AddConnection( NETRESOURCE & NetRC, DWORD Flags = 0, LPTSTR UserName = 0, LPTSTR Password = 0 ); // Cancel a network-connection. Returns TRUE on success; FALSE on // failure. The NetError() method (see below) will be called on // failure. For further information see WNetCancelConnection2() // in the online-help. BOOL CancelConnection( LPTSTR szName, DWORD dwFlags = CONNECT_UPDATE_PROFILE, BOOL ForceDisconnect = FALSE ); BOOL CancelConnection( NETRESOURCE & NetRC, DWORD dwFlags = CONNECT_UPDATE_PROFILE, BOOL ForceDisconnect = FALSE ); protected: // overridables // OnHitResource will be called whenever the enumerator finds // a net resource. See "Enumerate()" above. virtual BOOL OnHitResource( NETRESOURCE & ) = 0; // Override the NetError() method, if you want to handle // errors in a different way than the default. Normally // NetError() retrieves a human readable error-reason and // stores this in "m_pszError" (see GetErrorString() above). // The default-implementation of NetError() returns FALSE // always. This will cause the enumerator to break off the // enumeration. You can handle minor errors (such as // ERROR_BAD_NETPATH) in your derived class and return TRUE // to continue the enumeration with the next resource: // BOOL CMyNetImpl :: NetError(DWORD dwErrNo, LPCTSTR pszFnc) { // if( dwErrNo == ERROR_BAD_NETPATH ) // // minor error: a resource is not accessible at this time // // return with next resource ... // return TRUE; // else // // serious error: break off the enumeration // return CNetwork::NetError(dwErrNo, pszFnc); // } virtual BOOL NetError( DWORD dwErrNo, LPCTSTR pszFunction ); private: // implementation BOOL Enumerate( LPNETRESOURCE, DWORD ); } ; ////////////////////////////////////////////////////////////////////////////// // CNetwork -- inlining ... inline LPCTSTR CNetwork :: GetErrorString() const { return m_pszError ; } inline BOOL CNetwork :: CancelConnection(NETRESOURCE & rNetRC, DWORD dwFlags, BOOL bForce) { return CancelConnection(rNetRC.lpLocalName, dwFlags, bForce); } inline BOOL CNetwork :: IsServer( NETRESOURCE & rNetRC_p ) const { return (rNetRC_p.dwDisplayType == RESOURCEDISPLAYTYPE_SERVER) ? TRUE : FALSE ; } inline BOOL CNetwork :: IsDomain( NETRESOURCE & rNetRC_p ) const { return (rNetRC_p.dwDisplayType == RESOURCEDISPLAYTYPE_DOMAIN) ? TRUE : FALSE ; } inline BOOL CNetwork :: IsShare( NETRESOURCE & rNetRC_p ) const { return (rNetRC_p.dwDisplayType == RESOURCEDISPLAYTYPE_SHARE) ? TRUE : FALSE ; } inline BOOL CNetwork :: IsGeneric( NETRESOURCE & rNetRC_p ) const { return (rNetRC_p.dwDisplayType == RESOURCEDISPLAYTYPE_GENERIC) ? TRUE : FALSE ; } inline LPCTSTR CNetwork :: GetLocalName( NETRESOURCE & rNetRC_p ) const { return rNetRC_p.lpLocalName ; } inline LPCTSTR CNetwork :: GetRemoteName( NETRESOURCE & rNetRC_p ) const { return rNetRC_p.lpRemoteName ; } inline LPCTSTR CNetwork :: GetComment( NETRESOURCE & rNetRC_p ) const { return rNetRC_p.lpComment ; } inline LPCTSTR CNetwork :: GetProvider( NETRESOURCE & rNetRC_p ) const { return rNetRC_p.lpProvider ; } inline BOOL CNetwork :: IsConnectable( NETRESOURCE & rNetRC_p ) const { return ( (rNetRC_p.dwScope == RESOURCE_GLOBALNET) && (RESOURCEUSAGE_CONNECTABLE == (rNetRC_p.dwUsage & RESOURCEUSAGE_CONNECTABLE)) ) ? TRUE : FALSE ; } #endif // Network_h