home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / wfc007.000 / src / cnetwork.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-22  |  1.5 KB  |  90 lines

  1. #include <wfc.h>
  2. #pragma hdrstop
  3.  
  4. /*
  5. ** Author: Samuel R. Blackburn
  6. ** CI$: 76300,326
  7. ** Internet: sammy@sed.csc.com
  8. **
  9. ** You can use it any way you like.
  10. */
  11.  
  12. #if defined( _DEBUG )
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /*
  18. ** CNetResourceInformation stuff
  19. */
  20.  
  21. IMPLEMENT_SERIAL( CNetwork, CObject, 1 )
  22.  
  23. CNetwork::CNetwork( LPCTSTR machine_name )
  24. {
  25.    m_WideMachineName = NULL;
  26.    m_MachineName.Empty();
  27.  
  28.    Open( machine_name );
  29. }
  30.  
  31. CNetwork::~CNetwork()
  32. {
  33.    Close();
  34. }
  35.  
  36. void CNetwork::Close( void )
  37. {
  38.    if ( m_WideMachineName != NULL )
  39.    {
  40.       delete [] m_WideMachineName;
  41.       m_WideMachineName = NULL;
  42.    }
  43.  
  44.    m_MachineName.Empty();
  45. }
  46.  
  47. DWORD CNetwork::GetErrorCode( void ) const
  48. {
  49.    return( m_ErrorCode );
  50. }
  51.  
  52. LPCTSTR CNetwork::GetMachineName( void )
  53. {
  54.    return( (LPCTSTR) m_MachineName );
  55. }
  56.  
  57. void CNetwork::Open( LPCTSTR machine_name )
  58. {
  59.    Close();
  60.  
  61.    if ( machine_name != NULL )
  62.    {
  63.       m_WideMachineName = new WCHAR[ ::strlen( machine_name ) + 1 ];
  64.  
  65. #if defined( UNICODE )
  66.       ::strcpy( m_WideMachineName, machine_name );
  67. #else
  68.       ::ASCII_to_UNICODE( machine_name, m_WideMachineName );
  69. #endif
  70.  
  71.       m_MachineName = machine_name;
  72.    }
  73. }
  74.  
  75. void CNetwork::Serialize( CArchive& archive )
  76. {
  77.    CObject::Serialize( archive );
  78.  
  79.    if ( archive.IsStoring() )
  80.    {
  81.       archive << m_MachineName;
  82.    }
  83.    else
  84.    {
  85.       CString temp_string;
  86.       archive >> temp_string;
  87.       Open( temp_string );
  88.    }
  89. }
  90.