// sxcon.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "sxcon.h" #include "sxconDlg.h" #include "orxconst.h" #include "orxcon.h" #ifdef R30SXC # include "sxconnls.h" #endif #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // Helpers BOOL CheckFileExists(CString filename) { CFile file; UINT flags; BOOL opened; flags = CFile::modeRead | CFile::typeBinary; opened = file.Open(filename, flags | CFile::shareDenyNone); if (! opened) opened = file.Open(filename, flags | CFile::shareCompat); if (opened) file.Close(); return opened; } static BOOL ParseOption(LPTSTR lpszCmdLine, LPCTSTR lpszOption, CString **pcstrValue) { int nLen = lstrlen(lpszOption); BOOL bCheck = TRUE; BOOL bFound = FALSE; LPTSTR lpszBegin = lpszCmdLine; if (pcstrValue) *pcstrValue = NULL; while (*lpszCmdLine != 0) { if ((*lpszCmdLine == (TCHAR)' ') || (*lpszCmdLine == (TCHAR)'\t')) { // strip leading white spaces int isp = 0; while ((*(lpszCmdLine+isp) == (TCHAR)' ') || (*(lpszCmdLine+isp) == (TCHAR)'\t')) { isp++; } if (lpszCmdLine != lpszBegin) isp--; // leave one // wipe extra spaces if (isp) { int nCmdLen = lstrlen(lpszCmdLine); memmove(lpszCmdLine, lpszCmdLine + isp, (nCmdLen - isp + 1) * sizeof(TCHAR)); } // start checking for command options bCheck = TRUE; if ((*(lpszCmdLine+isp) == (TCHAR)' ') || (*(lpszCmdLine+isp) == (TCHAR)'\t')) lpszCmdLine++; continue; } if (bCheck && ((*lpszCmdLine == (TCHAR)'/') || (*lpszCmdLine == (TCHAR)'-'))) { int nCmdLen = lstrlen(lpszCmdLine); memmove(lpszCmdLine, lpszCmdLine + 1, (nCmdLen) * sizeof(TCHAR)); continue; } if (bCheck && _tcsnicmp(lpszOption, lpszCmdLine, nLen) == 0) { // remove the option from the command line int nCmdLen = lstrlen(lpszCmdLine); memmove(lpszCmdLine, lpszCmdLine + nLen, (nCmdLen - nLen +1) * sizeof(TCHAR)); if ((*lpszCmdLine == (TCHAR)'=') || (*lpszCmdLine == (TCHAR)':')) { nLen = 0; LPTSTR lpszOptVal = lpszCmdLine+1; TCHAR ch = *(lpszOptVal); int iq = ((ch == (TCHAR)'\"') || (ch == (TCHAR)'\'')) ? 1 : 0; if (iq) { nLen++; lpszOptVal++; } do { nLen++; ch = *(lpszCmdLine+nLen); } while ((ch != 0) && (ch != (TCHAR)' ') && (ch != (TCHAR)'\t') && (ch != (TCHAR)'\"') && (ch != (TCHAR)'\'')); if ((ch == (TCHAR)'\"') || (ch == (TCHAR)'\'')) { iq ++; *(lpszCmdLine+nLen) = (TCHAR)' '; // wipe out } if (pcstrValue) *pcstrValue = new CString((LPCTSTR)lpszOptVal, nLen-iq); if (*pcstrValue) (*pcstrValue)->TrimRight(); // delete right spaces int nCmdLen = lstrlen(lpszCmdLine); memmove(lpszCmdLine, lpszCmdLine + nLen, (nCmdLen - nLen + 1) * sizeof(TCHAR)); } bFound = TRUE; break; } bCheck = FALSE; lpszCmdLine++; } return bFound; } ///////////////////////////////////////////////////////////////////////////// // CSxConApp BEGIN_MESSAGE_MAP(CSxConApp, CWinApp) //{{AFX_MSG_MAP(CSxConApp) // 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::OnHelpFinder) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSxConApp construction CSxConApp::CSxConApp() { // Place all significant initialization in InitInstance # ifdef _DEBUG m_bDoDebugBreaks = FALSE; # endif m_cstrReport = NULL; m_cstrRepSrv = NULL; m_cstrUserId = NULL; m_cstrParams = NULL; m_cstrDesName = NULL; m_eDesType = orODInReport; m_eCallMode = orCMCallAsync; m_cstrSysUserId = NULL; } CSxConApp::~CSxConApp() { } void CSxConApp::ParseCommandLine() { if (!m_lpCmdLine) m_lpCmdLine = _T(""); // Check passed command line for parameters # ifdef _DEBUG m_bDoDebugBreaks = ParseOption(m_lpCmdLine, _T("debug"), NULL); # endif if (m_lpCmdLine[0] == 0) { // someone run us without parameters m_bShowUI = TRUE; m_bStayUp = TRUE; # ifdef _DEBUG m_bShowAct = TRUE; # else m_bShowAct = FALSE; # endif return; } m_bStayUp = ParseOption(m_lpCmdLine, _T("stayup"), NULL); m_bShowUI = ParseOption(m_lpCmdLine, _T("showui"), NULL); m_bSetOpt = ParseOption(m_lpCmdLine, _T("setopt"), NULL); m_bShowAct = ParseOption(m_lpCmdLine, _T("showact"), NULL); // force UI up if ready for multiple runs if (m_bStayUp && !m_bShowUI) m_bShowUI = TRUE; BOOL b; b = ParseOption(m_lpCmdLine, _T("report"), &m_cstrReport); if (!b) b = ParseOption(m_lpCmdLine, _T("module"), &m_cstrReport); b = ParseOption(m_lpCmdLine, _T("server"), &m_cstrRepSrv); b = ParseOption(m_lpCmdLine, _T("userid"), &m_cstrUserId); b = ParseOption(m_lpCmdLine, _T("desname"), &m_cstrDesName); b = ParseOption(m_lpCmdLine, _T("authid"), &m_cstrSysUserId); CString *pstr = (CString*)NULL; m_eDesType = orODInReport; // init b = ParseOption(m_lpCmdLine, _T("destype"), &pstr); if (b && pstr) { if (pstr->IsEmpty()) m_eDesType = orODInReport; else if (!pstr->CompareNoCase(_T("InReport"))) m_eDesType = orODInReport; else if (!pstr->CompareNoCase(_T("LocalFile"))) m_eDesType = orODToLocalFile; else if (!pstr->CompareNoCase(_T("File"))) m_eDesType = orODToFile; else if (!pstr->CompareNoCase(_T("Printer"))) m_eDesType = orODToPrinter; else if (!pstr->CompareNoCase(_T("Mail"))) m_eDesType = orODToMail; else if (!pstr->CompareNoCase(_T("Screen"))) m_eDesType = orODToScreen; else if (!pstr->CompareNoCase(_T("Preview"))) m_eDesType = orODToPreview; else if (!pstr->CompareNoCase(_T("Cache"))) m_eDesType = orODToServerCache; delete (CString*)pstr; } m_eCallMode = orCMCallAsync; // init b = ParseOption(m_lpCmdLine, _T("callmode"), &pstr); if (b && pstr) { if (pstr->IsEmpty()) m_eCallMode = orCMCallAsync; else if (!pstr->CompareNoCase(_T("Local"))) m_eCallMode = orCMCallLocal; else if (!pstr->CompareNoCase(_T("Sync"))) m_eCallMode = orCMCallSync; else if (!pstr->CompareNoCase(_T("Async"))) m_eCallMode = orCMCallAsync; delete (CString*)pstr; } m_cstrParams = new (CString); // rest of the cmd line (*m_cstrParams) = m_lpCmdLine; m_cstrParams->TrimRight(); // delete trailing spaces } ///////////////////////////////////////////////////////////////////////////// // The one and only CSxConApp object CSxConApp theApp; CSxConApp *AfxSxConGetApp() { return &theApp; } ///////////////////////////////////////////////////////////////////////////// // CSxConApp initialization BOOL CSxConApp::InitInstance() { # ifdef R30SXC // Set locale - do this before loading the DLL since the DLL name // depends on the locale SetOracleLocale(); // Load resource DLL if (!LoadResourceDLL()) { return FALSE; } // Set location of Help file HelpSetFilePath(); # endif R30SXC // CG: This line was added by the OLE Control Containment component AfxEnableControlContainer(); // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // When a server application is launched stand-alone, it is a good idea // to update the system registry in case it has been damaged. COleObjectFactory::UpdateRegistryAll(); ParseCommandLine(); DEBUG_BREAK; CSxConDlg dlg; m_pMainWnd = &dlg; // start dialog, this will instantiate our control int nResponse; if (m_bShowUI) nResponse = dlg.DoModal(); else nResponse = dlg.DoBatch(); // // MFC EndDialog(-1) if control cannot be created - // HRESULT (typically 0x8007007E on CoCreateInstance) unfortunately is // not passed around... So much for MFC. // It's too late to pop a MessageBox here anyway. // // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; } BEGIN_DISPATCH_MAP(CSxConApp, CWinApp) //{{AFX_DISPATCH_MAP(CSxConApp) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_DISPATCH_MAP END_DISPATCH_MAP() // Note: we add support for IID_ISxConApp to support typesafe binding // from VBA. This IID must match the GUID that is attached to the // dispinterface in the .ODL file. // {77F65215-BE46-11CF-AD43-0020AF0BA9E2} static const IID IID_ISxConApp = { 0x77f65215, 0xbe46, 0x11cf, { 0xad, 0x43, 0x0, 0x20, 0xaf, 0xb, 0xa9, 0xe2 } }; BEGIN_INTERFACE_MAP(CSxConApp, CWinApp) INTERFACE_PART(CSxConApp, IID_ISxConApp, Dispatch) END_INTERFACE_MAP() int CSxConApp::ExitInstance() { if (m_cstrReport) delete m_cstrReport; if (m_cstrRepSrv) delete m_cstrRepSrv; if (m_cstrUserId) delete m_cstrUserId; if (m_cstrParams) delete m_cstrParams; if (m_cstrDesName) delete m_cstrDesName; if (m_cstrSysUserId) delete m_cstrSysUserId; return CWinApp::ExitInstance(); }