/* ======================================================================================= Name :MngData5.cpp Author : VL Date :10/07/97 Description : Defines the class behaviors for the MngData5 application. ======================================================================================= Modification -> Author : Date : Description : ======================================================================================= */ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ #include "stdafx.h" #include #include "MngData5.h" #include "DlgMain.h" #include "winsock2.h" /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* ======================================================================================= Globals ======================================================================================= */ /* * The one and only CMngDataApp object */ CMngDataApp theApp; HANDLE g_hMutex; /* ======================================================================================= CMngDataApp ======================================================================================= */ /* ------------------------------------------------------------------------------ message map ------------------------------------------------------------------------------ */ BEGIN_MESSAGE_MAP(CMngDataApp, CWinApp) //{{AFX_MSG_MAP(CMngDataApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() /* ------------------------------------------------------------------------------ constructor ------------------------------------------------------------------------------ */ CMngDataApp::CMngDataApp() { } /* ------------------------------------------------------------------------------ initialization ------------------------------------------------------------------------------ */ BOOL CMngDataApp::InitInstance() { #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif /* * create mutex to be sure that there's only one instance at same time */ g_hMutex = CreateMutex( NULL, FALSE, "Vss data manager application" ); if (GetLastError() == ERROR_ALREADY_EXISTS) { ReleaseMutex( g_hMutex ); AfxMessageBox( "Vss data manager is already running", MB_ICONSTOP ); return FALSE; } /* * Init OLE */ if (!AfxOleInit()) { AfxMessageBox("OLE initialization failed.\r\nMake sure that the OLE libraries\r\nare the correct version.", MB_ICONSTOP); return FALSE; } /* * init windows socket */ if ( !fn_bInitWindowsSocket() != 0 ) return FALSE; /* * display main dialog box */ CMngDataDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { } else if (nResponse == IDCANCEL) { } fn_vCloseWindowsSocket(); return FALSE; } /* ------------------------------------------------------------------------------ Exit program : release mutex ------------------------------------------------------------------------------ */ int CMngDataApp::ExitInstance() { ReleaseMutex( g_hMutex ); return CWinApp::ExitInstance(); } /* ======================================================================================= Specific functions ======================================================================================= */ /* ---------------------------------------------------------------------------------------- Description : initialize winsows socket to communicate with time server Returns (BOOL ) true if init success ---------------------------------------------------------------------------------------- */ BOOL CMngDataApp::fn_bInitWindowsSocket( void ) { WORD wVersionRequested; WSADATA wsaData; int iError; wVersionRequested = MAKEWORD( 2, 0 ); iError = WSAStartup( wVersionRequested, &wsaData ); if ( iError != 0 ) { AfxMessageBox( "Cannot initialize windows socket", MB_ICONSTOP ); return FALSE; } return TRUE; } /* ---------------------------------------------------------------------------------------- Description : close windows socket ---------------------------------------------------------------------------------------- */ void CMngDataApp::fn_vCloseWindowsSocket( void ) { WSACleanup(); }