PageRenderTime 48ms CodeModel.GetById 18ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

/reporting/crashsender/CrashSender.cpp

http://crashrpt.googlecode.com/
C++ | 139 lines | 77 code | 24 blank | 38 comment | 9 complexity | b6441c1f12c56f4bd04addf9fb87dc90 MD5 | raw file
  1/************************************************************************************* 
  2This file is a part of CrashRpt library.
  3Copyright (c) 2003-2013 The CrashRpt project authors. All Rights Reserved.
  4
  5Use of this source code is governed by a BSD-style license
  6that can be found in the License.txt file in the root of the source
  7tree. All contributing project authors may
  8be found in the Authors.txt file in the root of the source tree.
  9***************************************************************************************/
 10
 11// File: CrashSender.cpp
 12// Description: Entry point to the application. 
 13// Authors: zexspectrum
 14// Date: 2010
 15
 16#include "stdafx.h"
 17#include "resource.h"
 18#include "ErrorReportDlg.h"
 19#include "ResendDlg.h"
 20#include "CrashInfoReader.h"
 21#include "strconv.h"
 22#include "Utility.h"
 23
 24CAppModule _Module;             // WTL's application module.
 25
 26int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int /*nCmdShow*/ = SW_SHOWDEFAULT)
 27{ 
 28	int nRet = 0; // Return code
 29	CErrorReportDlg dlgErrorReport; // Error Report dialog
 30	CResendDlg dlgResend; // Resend dialog
 31
 32	// Get command line parameters.
 33	LPCWSTR szCommandLine = GetCommandLineW();
 34
 35    // Split command line.
 36    int argc = 0;
 37    LPWSTR* argv = CommandLineToArgvW(szCommandLine, &argc);
 38
 39    // Check parameter count.
 40    if(argc!=2)
 41        return 1; // No arguments passed, exit.
 42
 43	if(_tcscmp(argv[1], _T("/terminate"))==0)
 44	{
 45		// User wants us to find and terminate all instances of CrashSender.exe
 46		return CErrorReportSender::TerminateAllCrashSenderProcesses();
 47	}
 48
 49	// Extract file mapping name from command line arg.    
 50    CString sFileMappingName = CString(argv[1]);
 51		
 52	// Create the sender model that will collect crash report data 
 53	// and send error report(s).
 54	CErrorReportSender* pSender = CErrorReportSender::GetInstance();
 55
 56	// Init the sender object
 57	BOOL bInit = pSender->Init(sFileMappingName.GetBuffer(0));
 58	if(!bInit)
 59    {
 60		// Failed to init 
 61		delete pSender;
 62        return 0;
 63    }      
 64
 65	// Determine what to do next 
 66	// (either run in GUI more or run in silent mode).
 67	if(!pSender->GetCrashInfo()->m_bSilentMode)
 68	{
 69		// GUI mode.
 70		// Create message loop.
 71		CMessageLoop theLoop;
 72		_Module.AddMessageLoop(&theLoop);
 73
 74		if(!pSender->GetCrashInfo()->m_bSendRecentReports)
 75		{
 76			// Create "Error Report" dialog			
 77			if(dlgErrorReport.Create(NULL) == NULL)
 78			{
 79				ATLTRACE(_T("Error report dialog creation failed!\n"));
 80				delete pSender;
 81				return 1;
 82			}			
 83		}
 84		else
 85		{        
 86			// Create "Send Error Reports" dialog.					
 87			if(dlgResend.Create(NULL) == NULL)
 88			{
 89				ATLTRACE(_T("Resend dialog creation failed!\n"));
 90				delete pSender;
 91				return 1;
 92			}			
 93		}
 94
 95		// Process window messages.
 96		nRet = theLoop.Run();	    
 97		_Module.RemoveMessageLoop();
 98	}
 99	else
100	{
101		// Silent (non-GUI mode).
102		// Run the sender and wait until it exits.
103		pSender->Run();
104		pSender->WaitForCompletion();
105		// Get return status
106		nRet = pSender->GetStatus();
107	}
108    
109	// Delete sender object.
110	delete pSender;
111
112	// Exit.
113    return nRet;
114}
115
116int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
117{  
118    HRESULT hRes = ::CoInitialize(NULL);
119    // If you are running on NT 4.0 or higher you can use the following call instead to 
120    // make the EXE free threaded. This means that calls come in on a random RPC thread.
121    //	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
122    ATLASSERT(SUCCEEDED(hRes));
123
124    // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
125    ::DefWindowProc(NULL, 0, 0, 0L);
126
127    AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES);	// add flags to support other controls
128
129    hRes = _Module.Init(NULL, hInstance);
130    ATLASSERT(SUCCEEDED(hRes));
131
132    int nRet = Run(lpstrCmdLine, nCmdShow);
133
134    _Module.Term();
135    ::CoUninitialize();
136
137    return nRet;
138}
139