// SmsCenter.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "SmsCenter.h"
#include "SmsCenterDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSmsCenterApp
#include <Psapi.h>
#include "..\public\MiniDmp\MiniDmp.h"

BEGIN_MESSAGE_MAP(CSmsCenterApp, CWinApp)
	//{{AFX_MSG_MAP(CSmsCenterApp)
		// 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()

/////////////////////////////////////////////////////////////////////////////
// CSmsCenterApp construction

CSmsCenterApp::CSmsCenterApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CSmsCenterApp object

CSmsCenterApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CSmsCenterApp initialization
//#include "..\..\shou-e\RN_Eri\blowfish_Eri.h"
BOOL CSmsCenterApp::InitInstance()
{
/*	
	int a = sizeof(long);
	int b = sizeof(float);
	int c = sizeof(double);
	int d=sizeof(UCHAR);
	int e=sizeof(int);
*/

	//�����쳣��׽��������minidump�ļ�
//#if _MSC_VER>=1300
//#ifdef _M_IX86
#ifndef _DEBUG
	GPTSetSetUnhandledExceptionFilter();  //��������
#endif
//#endif
//#endif

	AfxEnableControlContainer();
	//CoInitialize(NULL);
	CoInitializeEx( NULL , COINIT_MULTITHREADED );

	// 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

/*
	if ( FindProcess(_T("SmsCenter.exe"))>1 )
	{
		int iRet = MessageBox(NULL,_T("�������˶��ŷ�������س��򣬿��ܴ��ڲ�ͬ���û�������!\r\n�Ƿ����������") , _T("����") , MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 );
		if ( iRet != IDYES )
			return false;
	}
*/

	CSmsCenterDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

int CSmsCenterApp::ExitInstance() 
{
	CoUninitialize();

	return CWinApp::ExitInstance();
}

long CSmsCenterApp::FindProcess(const TCHAR *pName)
{
	long lCount=0;
	BOOL bReBoot = false;
	DWORD aProcesses[1024], cbNeeded, cProcesses;
	unsigned int i;
	//ö��ϵͳ����ID�б�
	if ( EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
	{
		// Calculate how many process identifiers were returned.
		//�����������
		cProcesses = cbNeeded / sizeof(DWORD);
		// ���ÿ�����̵����ƺ�ID
		TCHAR szProcessName[MAX_PATH]={0};
		for ( i = 0; i < cProcesses; i++ )
		{
			memset( szProcessName ,0, sizeof(szProcessName) );
			CSmsCenterDlg::GetProcessNameAndID( aProcesses[i],szProcessName);
			//if ( !strcmp( szProcessName , pName ) ) //����Dh2000�Ľ�����
			if ( !_tcsncmp( szProcessName , pName , _tcslen(pName) ) ) //����Dh2000�Ľ�����
			{
				lCount ++;
			}
		}
	}
	return lCount;
}