// ************************************************************************** // OnInitDialog () // // Description: // Called immediately before the dialog box is displayed. Use opportunity // to initialize controls. // // Parameters: // none // // Returns: // BOOL - TRUE. // ************************************************************************** BOOL CKServerStatusPage::OnInitDialog () { IOPCServer *pIServer = NULL; OPCSERVERSTATUS *pServerStatus; CString strLoader; CString strStatus; CString strTemp; // Perform default processing: CPropertyPage::OnInitDialog (); // Get IServer interface: ASSERT (m_pServer != NULL); pIServer = m_pServer->GetIServer (); // Add server name to status string: strLoader.FormatMessage (IDS_PROGID, m_pServer->GetProgID ()); strStatus += strLoader; // Add remote machine (if applicable) to status string: if (m_pServer->GetRemoteMachine ()) { strLoader.FormatMessage (IDS_REMOTEMACHINE, m_pServer->GetRemoteMachine ()); strStatus += strLoader; } // Get the server status: if (pIServer && SUCCEEDED (pIServer->GetStatus (&pServerStatus)) && pServerStatus) { FILETIME ftLocal; TCHAR szBuffer [DEFBUFFSIZE]; // Add vendor name to status string: if (pServerStatus->szVendorInfo) { // Convert venter name from UNICODE if needed: #ifdef _UNICODE lstrcpyn (szBuffer, pServerStatus->szVendorInfo, sizeof (szBuffer) / sizeof (TCHAR)); #else _wcstombsz (szBuffer, pServerStatus->szVendorInfo, sizeof (szBuffer) / sizeof (TCHAR)); #endif // Add vender name: strLoader.FormatMessage (IDS_VENDORNAME, szBuffer); strStatus += strLoader; // Free memory allocated for vender info: CoTaskMemFree (pServerStatus->szVendorInfo); } // Add start time to status string: if (FileTimeToLocalFileTime (&pServerStatus->ftStartTime, &ftLocal)) { SYSTEMTIME systime; if (FileTimeToSystemTime (&ftLocal, &systime)) { strTemp.Format (_T("%02d:%02d:%02d:%03d"), systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds); strLoader.FormatMessage (IDS_STARTTIME, strTemp); strStatus += strLoader; } } // Add current time to status string: if (FileTimeToLocalFileTime (&pServerStatus->ftCurrentTime, &ftLocal)) { SYSTEMTIME systime; if (FileTimeToSystemTime (&ftLocal, &systime)) { strTemp.Format (_T("%02d:%02d:%02d:%03d"), systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds); strLoader.FormatMessage (IDS_CURRENTTIME, strTemp); strStatus += strLoader; } } // Add last update time to status string: if (FileTimeToLocalFileTime (&pServerStatus->ftLastUpdateTime, &ftLocal)) { SYSTEMTIME systime; if (FileTimeToSystemTime (&ftLocal, &systime)) { strTemp.Format (_T("%02d:%02d:%02d:%03d"), systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds); strLoader.FormatMessage (IDS_LASTUPDATETIME, strTemp); strStatus += strLoader; } } // Create a string describing server state: switch (pServerStatus->dwServerState) { case OPC_STATUS_RUNNING: strTemp.LoadString (IDS_RUNNING); strLoader.FormatMessage (IDS_SERVERSTATE, strTemp); break; case OPC_STATUS_FAILED: strTemp.LoadString (IDS_FAILED); strLoader.FormatMessage (IDS_SERVERSTATE, strTemp); break; case OPC_STATUS_NOCONFIG: strTemp.LoadString (IDS_NOCONFIG); strLoader.FormatMessage (IDS_SERVERSTATE, strTemp); break; case OPC_STATUS_SUSPENDED: strTemp.LoadString (IDS_SUSPENDED); strLoader.FormatMessage (IDS_SERVERSTATE, strTemp); break; case OPC_STATUS_TEST: strTemp.LoadString (IDS_TEST); strLoader.FormatMessage (IDS_SERVERSTATE, strTemp); break; default: strLoader.FormatMessage (IDS_SERVERSTATE, _T("???")); break; } // Add server state to status string: strStatus += strLoader; // Add group count to status string: strTemp.Format (_T("%d"), pServerStatus->dwGroupCount); strLoader.FormatMessage (IDS_GROUPCOUNT, strTemp); strStatus += strLoader; // Add major version number to status string: strTemp.Format (_T("%d"), pServerStatus->wMajorVersion); strLoader.FormatMessage (IDS_MAJORVERSION, strTemp); strStatus += strLoader; // Add minor version to status string: strTemp.Format (_T("%d"), pServerStatus->wMinorVersion); strLoader.FormatMessage (IDS_MINORVERSION, strTemp); strStatus += strLoader; // Add build number to status string: strTemp.Format (_T("%d"), pServerStatus->wBuildNumber); strLoader.FormatMessage (IDS_BUILDNUMBER, strTemp); strStatus += strLoader; // Free memeory allocated for server status: CoTaskMemFree (pServerStatus); } // Else if failed, add string stating unable to determin server status // to status string: else { strLoader.LoadString (IDS_UNABLE_TO_DETERMINE_STATUS); strStatus += strLoader; } // Display the status string: ((CStatic *) GetDlgItem (IDC_STATUS))->SetWindowText (strStatus); // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE return (TRUE); }
//=============================================================================* string BAR_CSCOnlineProxy::ReadControlVersion() //=============================================================================* { BAR_TRACE(4, "read control version"); if ( ! IsLoggedIn() ) { Throw_FatalError(L"can not read control version before logged in"); } //=== instantiate opc server // BAR_TypeLib* pTlb = NULL; // IOPCServer* pIOPCServer = (IOPCServer*)CreateInstance("opc server", // IID_IOPCServer, // CLSID_OPCServer, // m_sRemoteHost, // "OPCDA", // LIBID_OPCDA, // "2", // pTlb); //=== instantiate opc server IOPCServer* pIOPCServer = (IOPCServer*) CreateInstance("opc server", IID_IOPCServer, CLSID_OPCServer, m_sRemoteHost, false, "CSC_Onl_Srv", /*LIBID_OPCDA*/LIBID_CSC_Srv_Lib, "1", m_pTlbCSCOnlSrv); //=== get status item OPCSERVERSTATUS *pStatus = NULL; HRESULT hr = pIOPCServer->GetStatus(&pStatus); if ( FAILED(hr) ) { Throw_ReadControlVersionFailed(hr); } if ( pStatus == NULL ) { Throw_FatalError(L"opc server status is null"); } WORD wMajorVersion = pStatus->wMajorVersion; WORD wMinorVersion = pStatus->wMinorVersion; ::CoTaskMemFree(pStatus); //=== build version string ostringstream ossControlVersion; ossControlVersion << (int)wMajorVersion << "." << (int)wMinorVersion; string sControlVersion = ossControlVersion.str(); //=== release opc server if ( pIOPCServer != NULL ) { pIOPCServer->Release(); } /* //=== unregister type library if ( pTlb != NULL ) { delete pTlb; } */ //=== finished BAR_TRACE1(1, "control version=%s", sControlVersion.c_str()); return sControlVersion.c_str(); }