testtoolsconn/stat/desktop/testsource/dlltester/src/dlltestdlg.cpp
changeset 0 3da2a79470a7
equal deleted inserted replaced
-1:000000000000 0:3da2a79470a7
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // dlltestDlg.cpp : implementation file
       
    22 //
       
    23 
       
    24 #include "stdafx.h"
       
    25 #include "dlltest.h"
       
    26 #include "dlltestDlg.h"
       
    27 
       
    28 #include <utils.h>
       
    29 #include <statexp.h>
       
    30 
       
    31 #ifdef _DEBUG
       
    32 #define new DEBUG_NEW
       
    33 #undef THIS_FILE
       
    34 static char THIS_FILE[] = __FILE__;
       
    35 #endif
       
    36 
       
    37 // function pointer prototypes
       
    38 typedef	char * (*LPFN_Version)();
       
    39 typedef	char * (*LPFN_GetError)(const int handle);
       
    40 typedef	int (*LPFN_SetConnectionLogging)(const char * filename);
       
    41 typedef	void (*LPFN_CloseConnectionLogging)();
       
    42 typedef	int (*LPFN_Connect)(const STATCONNECTTYPE iConnectType, const char * pszPlatformType);
       
    43 typedef	int (*LPFN_Disconnect)(const int handle);
       
    44 typedef	int (*LPFN_SetCommandDelay)(const int handle, const unsigned int iMillisecondDelay);
       
    45 typedef	int (*LPFN_SetCommandLogging)(const int handle, const char * pszLogPath, HWND messageWindow, const STATLOGLEVEL iLevel, const bool bAppend);
       
    46 typedef	int (*LPFN_SetImageVerification)(const int handle, const char * pszRefDir, const bool bRemoveOldImages, const int iFactor);
       
    47 typedef	int (*LPFN_SendRawCommand)(const int handle, const char * pszText);
       
    48 typedef	int (*LPFN_SendCommandFile)(const int handle, const char * pszFile);
       
    49 typedef	int (*LPFN_GetSnapshot)(const int handle, TBitmapFileHeader **ppFile, TBitmapInfoHeader **ppBitmap, char **ppData, unsigned long *pSize);
       
    50 
       
    51 // initialise pointers
       
    52 LPFN_Version pfn_Version = NULL;
       
    53 LPFN_GetError pfn_GetError = NULL;
       
    54 LPFN_SetConnectionLogging pfn_SetConnectionLogging = NULL;
       
    55 LPFN_CloseConnectionLogging pfn_CloseConnectionLogging = NULL;
       
    56 LPFN_Connect pfn_Connect = NULL;
       
    57 LPFN_Disconnect pfn_Disconnect = NULL;
       
    58 LPFN_SetCommandDelay pfn_SetCommandDelay = NULL;
       
    59 LPFN_SetCommandLogging pfn_SetCommandLogging = NULL;
       
    60 LPFN_SetImageVerification pfn_SetImageVerification = NULL;
       
    61 LPFN_SendRawCommand pfn_SendRawCommand = NULL;
       
    62 LPFN_SendCommandFile pfn_SendCommandFile = NULL;
       
    63 LPFN_GetSnapshot pfn_GetSnapshot = NULL;
       
    64 
       
    65 //////////////////////////////////////////////////////////////////////////
       
    66 // This is the main thread function which listens on a socket and
       
    67 // processes any incoming scripts
       
    68 DWORD WINAPI
       
    69 ThreadProc(LPVOID lpParameter)
       
    70 {
       
    71 	CDlltestDlg *pWorker = (CDlltestDlg *)lpParameter;
       
    72 
       
    73 	pWorker->Run();
       
    74 
       
    75 	return 1;
       
    76 }
       
    77 
       
    78 
       
    79 /////////////////////////////////////////////////////////////////////////////
       
    80 // CAboutDlg dialog used for App About
       
    81 
       
    82 class CAboutDlg : public CDialog
       
    83 {
       
    84 public:
       
    85 	CAboutDlg();
       
    86 
       
    87 // Dialog Data
       
    88 	//{{AFX_DATA(CAboutDlg)
       
    89 	enum { IDD = IDD_ABOUTBOX };
       
    90 	//}}AFX_DATA
       
    91 
       
    92 	// ClassWizard generated virtual function overrides
       
    93 	//{{AFX_VIRTUAL(CAboutDlg)
       
    94 	protected:
       
    95 	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
       
    96 	//}}AFX_VIRTUAL
       
    97 
       
    98 // Implementation
       
    99 protected:
       
   100 	//{{AFX_MSG(CAboutDlg)
       
   101 	//}}AFX_MSG
       
   102 	DECLARE_MESSAGE_MAP()
       
   103 };
       
   104 
       
   105 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
       
   106 {
       
   107 	//{{AFX_DATA_INIT(CAboutDlg)
       
   108 	//}}AFX_DATA_INIT
       
   109 }
       
   110 
       
   111 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
       
   112 {
       
   113 	CDialog::DoDataExchange(pDX);
       
   114 	//{{AFX_DATA_MAP(CAboutDlg)
       
   115 	//}}AFX_DATA_MAP
       
   116 }
       
   117 
       
   118 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
       
   119 	//{{AFX_MSG_MAP(CAboutDlg)
       
   120 		// No message handlers
       
   121 	//}}AFX_MSG_MAP
       
   122 END_MESSAGE_MAP()
       
   123 
       
   124 /////////////////////////////////////////////////////////////////////////////
       
   125 // CDlltestDlg dialog
       
   126 
       
   127 CDlltestDlg::CDlltestDlg(CWnd* pParent /*=NULL*/)
       
   128 	: CDialog(CDlltestDlg::IDD, pParent)
       
   129 {
       
   130 	//{{AFX_DATA_INIT(CDlltestDlg)
       
   131 		// NOTE: the ClassWizard will add member initialization here
       
   132 	//}}AFX_DATA_INIT
       
   133 	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
       
   134 }
       
   135 
       
   136 void CDlltestDlg::DoDataExchange(CDataExchange* pDX)
       
   137 {
       
   138 	CDialog::DoDataExchange(pDX);
       
   139 	//{{AFX_DATA_MAP(CDlltestDlg)
       
   140 	DDX_Control(pDX, IDC_OVERWRITE, m_RemoveImages);
       
   141 	DDX_Control(pDX, IDC_RUN, m_Run);
       
   142 	DDX_Control(pDX, IDC_CHKLOGTOFILE, m_ChkLogtofile);
       
   143 	DDX_Control(pDX, IDC_BROWSESNAPSHOT, m_BrowseSnapshot);
       
   144 	DDX_Control(pDX, IDC_BROWSEREFIMAGES, m_BrowseRefImages);
       
   145 	DDX_Control(pDX, IDC_BROWSELOG, m_BrowseLog);
       
   146 	DDX_Control(pDX, IDC_BROWSECMDFILE, m_BrowseCmdFile);
       
   147 	DDX_Control(pDX, IDC_CHECKCMDFILE, m_CheckCmdFile);
       
   148 	DDX_Control(pDX, IDC_CHECKVERIFICATION, m_CheckVerification);
       
   149 	DDX_Control(pDX, IDC_CHECKSNAPSHOT, m_CheckSnapshot);
       
   150 	DDX_Control(pDX, IDC_CHECKRAWCMD, m_CheckRawCmd);
       
   151 	DDX_Control(pDX, IDC_ADDRESS, m_Address);
       
   152 	DDX_Control(pDX, IDC_CONNECTION, m_Connection);
       
   153 	DDX_Control(pDX, IDC_PROGRESS, m_Progress);
       
   154 	DDX_Control(pDX, IDC_SNAPSHOT, m_Snapshot);
       
   155 	DDX_Control(pDX, IDC_DELAY, m_Delay);
       
   156 	DDX_Control(pDX, IDC_FUDGE, m_Fudge);
       
   157 	DDX_Control(pDX, IDC_REFDIR, m_RefDir);
       
   158 	DDX_Control(pDX, IDC_RAWCMD, m_RawCmd);
       
   159 	DDX_Control(pDX, IDC_LOGFILE, m_LogFile);
       
   160 	DDX_Control(pDX, IDC_CMDFILE, m_CmdFile);
       
   161 	DDX_Control(pDX, IDC_ITERATIONS, m_Iterations);
       
   162 	DDX_Control(pDX, IDC_PLATFORM, m_Platform);
       
   163 	DDX_Control(pDX, IDC_LINK, m_Link);
       
   164 	//}}AFX_DATA_MAP
       
   165 }
       
   166 
       
   167 BEGIN_MESSAGE_MAP(CDlltestDlg, CDialog)
       
   168 	//{{AFX_MSG_MAP(CDlltestDlg)
       
   169 	ON_WM_SYSCOMMAND()
       
   170 	ON_WM_PAINT()
       
   171 	ON_WM_QUERYDRAGICON()
       
   172 	ON_BN_CLICKED(IDC_RUN, OnRun)
       
   173 	ON_CBN_SELCHANGE(IDC_CONNECTION, OnChangeConnection)
       
   174 	ON_BN_CLICKED(IDC_RESETSETTINGS, OnResetsettings)
       
   175 	ON_BN_CLICKED(IDC_RESETTESTS, OnResettests)
       
   176 	ON_BN_CLICKED(IDC_BROWSELOG, OnBrowselog)
       
   177 	ON_BN_CLICKED(IDC_CHECKCMDFILE, OnCheckcmdfile)
       
   178 	ON_BN_CLICKED(IDC_CHECKRAWCMD, OnCheckrawcmd)
       
   179 	ON_BN_CLICKED(IDC_CHECKSNAPSHOT, OnChecksnapshot)
       
   180 	ON_BN_CLICKED(IDC_CHECKVERIFICATION, OnCheckverification)
       
   181 	ON_BN_CLICKED(IDC_BROWSECMDFILE, OnBrowsecmdfile)
       
   182 	ON_BN_CLICKED(IDC_BROWSESNAPSHOT, OnBrowsesnapshot)
       
   183 	ON_BN_CLICKED(IDC_BROWSEREFIMAGES, OnBrowserefimages)
       
   184 	ON_BN_CLICKED(IDC_CHKLOGTOFILE, OnChklogtofile)
       
   185 	//}}AFX_MSG_MAP
       
   186 END_MESSAGE_MAP()
       
   187 
       
   188 /////////////////////////////////////////////////////////////////////////////
       
   189 // CDlltestDlg message handlers
       
   190 
       
   191 BOOL CDlltestDlg::OnInitDialog()
       
   192 {
       
   193 	CDialog::OnInitDialog();
       
   194 
       
   195 	// Add "About..." menu item to system menu.
       
   196 
       
   197 	// IDM_ABOUTBOX must be in the system command range.
       
   198 	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
       
   199 	ASSERT(IDM_ABOUTBOX < 0xF000);
       
   200 
       
   201 	CMenu* pSysMenu = GetSystemMenu(FALSE);
       
   202 	if (pSysMenu != NULL)
       
   203 	{
       
   204 		CString strAboutMenu;
       
   205 		strAboutMenu.LoadString(IDS_ABOUTBOX);
       
   206 		if (!strAboutMenu.IsEmpty())
       
   207 		{
       
   208 			pSysMenu->AppendMenu(MF_SEPARATOR);
       
   209 			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
       
   210 		}
       
   211 	}
       
   212 
       
   213 	SetIcon(m_hIcon, TRUE);			// Set big icon
       
   214 	SetIcon(m_hIcon, FALSE);		// Set small icon
       
   215 
       
   216 	m_Snapshot.SetLimitText(sizeof(szBuffer));
       
   217 	m_RefDir.SetLimitText(sizeof(szBuffer));
       
   218 	m_RawCmd.SetLimitText(sizeof(szBuffer));
       
   219 	m_LogFile.SetLimitText(sizeof(szBuffer));
       
   220 	m_CmdFile.SetLimitText(sizeof(szBuffer));
       
   221 
       
   222 	// initialise our settings
       
   223 	OnResetsettings();
       
   224 	OnResettests();
       
   225 	ReadSettings();
       
   226 
       
   227 	return TRUE;  // return TRUE  unless you set the focus to a control
       
   228 }
       
   229 
       
   230 //////////////////////////////////////////////////////////////////////////////////////
       
   231 
       
   232 void CDlltestDlg::OnSysCommand(UINT nID, LPARAM lParam)
       
   233 {
       
   234 	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
       
   235 	{
       
   236 		CAboutDlg dlgAbout;
       
   237 		dlgAbout.DoModal();
       
   238 	}
       
   239 	else
       
   240 	{
       
   241 		CDialog::OnSysCommand(nID, lParam);
       
   242 	}
       
   243 }
       
   244 
       
   245 //////////////////////////////////////////////////////////////////////////////////////
       
   246 
       
   247 // If you add a minimize button to your dialog, you will need the code below
       
   248 //  to draw the icon.  For MFC applications using the document/view model,
       
   249 //  this is automatically done for you by the framework.
       
   250 
       
   251 void CDlltestDlg::OnPaint() 
       
   252 {
       
   253 	if (IsIconic())
       
   254 	{
       
   255 		CPaintDC dc(this); // device context for painting
       
   256 
       
   257 		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
       
   258 
       
   259 		// Center icon in client rectangle
       
   260 		int cxIcon = GetSystemMetrics(SM_CXICON);
       
   261 		int cyIcon = GetSystemMetrics(SM_CYICON);
       
   262 		CRect rect;
       
   263 		GetClientRect(&rect);
       
   264 		int x = (rect.Width() - cxIcon + 1) / 2;
       
   265 		int y = (rect.Height() - cyIcon + 1) / 2;
       
   266 
       
   267 		// Draw the icon
       
   268 		dc.DrawIcon(x, y, m_hIcon);
       
   269 	}
       
   270 	else
       
   271 	{
       
   272 		CDialog::OnPaint();
       
   273 	}
       
   274 }
       
   275 
       
   276 //////////////////////////////////////////////////////////////////////////////////////
       
   277 
       
   278 HCURSOR CDlltestDlg::OnQueryDragIcon()
       
   279 {
       
   280 	return (HCURSOR) m_hIcon;
       
   281 }
       
   282 
       
   283 //////////////////////////////////////////////////////////////////////////////////////
       
   284 
       
   285 void CDlltestDlg::OnRun() 
       
   286 {
       
   287 	if (bRunning)
       
   288 	{
       
   289 		if (IDYES == AfxMessageBox(_T("The work task has not completed its current job and stopping it now may cause it to be left in an unstable state.  Do you wish to abort the current task?"), MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2))
       
   290 		{
       
   291 			TerminateThread(hThreadHandle, (unsigned long)-1);
       
   292 			EnableFields(TRUE);
       
   293 		}
       
   294 	}
       
   295 	else
       
   296 	{
       
   297 		//call Run to run through the script (with no appending to log file in this case) - spawn a thread...
       
   298 		DWORD dwThreadID;
       
   299 		if (hThreadHandle = CreateThread( NULL,					// security attributes
       
   300 												0,				// stack size
       
   301 												ThreadProc,		// proc to call
       
   302 												this,			// proc parameter
       
   303 												0,				// creation flags
       
   304 												&dwThreadID))	// thread identifier
       
   305 		{
       
   306 			EnableFields(FALSE);
       
   307 
       
   308 			MSG msg;
       
   309 			while(WaitForSingleObject(hThreadHandle, STAT_THREAD_SLEEP_TIME) == WAIT_TIMEOUT)
       
   310 			{
       
   311 				PeekMessage(&msg, m_hWnd, 0, 0, PM_REMOVE);
       
   312 				DispatchMessage(&msg);
       
   313 			}
       
   314 
       
   315 			EnableFields(TRUE);
       
   316 		}
       
   317 	}
       
   318 }
       
   319 
       
   320 //////////////////////////////////////////////////////////////////////////////////////
       
   321 
       
   322 void CDlltestDlg::Run()
       
   323 {
       
   324 	struct TBitmapFileHeader *pFile = NULL;
       
   325 	struct TBitmapInfoHeader *pInfo = NULL;
       
   326 	char *pData = NULL;
       
   327 	char szPrevious[10] = {0};
       
   328 	char szRemaining[10] = {0};
       
   329 	unsigned long lSize = 0;
       
   330 
       
   331 	bErrors = false;
       
   332 
       
   333 	m_Progress.SetRange(0, 100);
       
   334 	m_Progress.SetPos(0);
       
   335 	m_Progress.SetStep(GetIncrement());
       
   336 
       
   337 	CString logFile;		// We use this file name throughout the
       
   338 							// function and we should save it.
       
   339 	CString logFilePath;	// Also, we have a bit of a mixture
       
   340 							// of calls to make to set up logging
       
   341 							// and some require a file name (and assume a
       
   342 							// folder) and some require a full path.
       
   343 							// Generate a full path (based on the file name
       
   344 							// above) and use whichever variable suits
       
   345 							// each function call.
       
   346 
       
   347 	if (m_ChkLogtofile.GetCheck())
       
   348 	{
       
   349 		m_LogFile.GetWindowText(logFile);
       
   350 		GetLogFilePath(logFile,logFilePath);
       
   351 	}
       
   352 
       
   353 	// connect to runtime dll
       
   354 	if (m_Link.GetCurSel() == 1)
       
   355 	{
       
   356 		// display version
       
   357 		MessageBox(Version(), "STAT DLL Version", MB_OK);
       
   358 
       
   359 		CWaitCursor oWait;
       
   360 
       
   361 		// log connections
       
   362 		if (m_ChkLogtofile.GetCheck())
       
   363 		{
       
   364 			if (0 != logFilePath.GetLength())
       
   365 			{
       
   366 				SetConnectionLogging(logFilePath);
       
   367 			}
       
   368 		}
       
   369 
       
   370 		// get the connect string
       
   371 		switch(m_Connection.GetCurSel())
       
   372 		{
       
   373 		case 1:	// serial
       
   374 		case 2:	// infra-red
       
   375 		case 3:	// bluetooth
       
   376 		case 4:	// USB
       
   377 			m_Platform.GetLBText(m_Platform.GetCurSel(), szBuffer);
       
   378 			break;
       
   379 		case 0:	// socket
       
   380 			m_Address.GetWindowText(szBuffer, sizeof(szBuffer));
       
   381 			break;
       
   382 		}
       
   383 
       
   384 		// connect
       
   385 		Evaluate(h = Connect((STATCONNECTTYPE)(m_Connection.GetCurSel() + 1), szBuffer, NULL, NULL), h);
       
   386 
       
   387 		if (h)
       
   388 		{
       
   389 			m_Progress.StepIt();
       
   390 			UpdateWindow();
       
   391 
       
   392 			// log commands
       
   393 			if (m_ChkLogtofile.GetCheck())
       
   394 			{
       
   395 				if (0 != logFile.GetLength())
       
   396 					Evaluate(SetCommandLogging(h, logFile, NULL, EVerbose, true, NULL, NULL), h);
       
   397 			}
       
   398 
       
   399 			if (!bErrors)
       
   400 			{
       
   401 				// set command delay
       
   402 				m_Delay.GetWindowText(szBuffer, sizeof(szBuffer));
       
   403 				iValue = atoi(szBuffer);
       
   404 				Evaluate(SetCommandDelay(h, iValue), h);
       
   405 			}
       
   406 
       
   407 			if (!bErrors)
       
   408 			{
       
   409 				// set image verification
       
   410 				if (m_CheckVerification.GetCheck())
       
   411 				{
       
   412 					m_Fudge.GetWindowText(szBuffer, sizeof(szBuffer));
       
   413 					iValue = atoi(szBuffer);
       
   414 					m_RefDir.GetWindowText(szBuffer, sizeof(szBuffer));
       
   415 					if (*szBuffer)
       
   416 						Evaluate(SetImageVerification(h, szBuffer, m_RemoveImages.GetCheck()?true:false, iValue), h);
       
   417 				}
       
   418 			}
       
   419 
       
   420 			m_Iterations.GetWindowText(szPrevious, sizeof(szPrevious));
       
   421 			int iMax = atoi(szPrevious);
       
   422 			for (int i=0;i<iMax;i++)
       
   423 			{
       
   424 				if (!bErrors)
       
   425 				{
       
   426 					// execute raw command
       
   427 					if (m_CheckRawCmd.GetCheck())
       
   428 					{
       
   429 						m_RawCmd.GetWindowText(szBuffer, sizeof(szBuffer));
       
   430 						if (*szBuffer)
       
   431 						{
       
   432 							Evaluate(SendRawCommand(h, szBuffer), h);
       
   433 							m_Progress.StepIt();
       
   434 							UpdateWindow();
       
   435 						}
       
   436 					}
       
   437 				}
       
   438 
       
   439 				if (!bErrors)
       
   440 				{
       
   441 					// execute command file
       
   442 					if (m_CheckCmdFile.GetCheck())
       
   443 					{
       
   444 						m_CmdFile.GetWindowText(szBuffer, sizeof(szBuffer));
       
   445 						if (*szBuffer)
       
   446 						{
       
   447 							Evaluate(SendCommandFile(h, szBuffer), h);
       
   448 							m_Progress.StepIt();
       
   449 							UpdateWindow();
       
   450 						}
       
   451 					}
       
   452 				}
       
   453 
       
   454 				if (!bErrors)
       
   455 				{
       
   456 					// get a snapshot
       
   457 					if (m_CheckSnapshot.GetCheck())
       
   458 					{
       
   459 						m_Snapshot.GetWindowText(szBuffer, sizeof(szBuffer));
       
   460 						if (*szBuffer)
       
   461 						{
       
   462 							DeleteFile(szBuffer);
       
   463 							Evaluate(GetSnapshot(h, &pFile, &pInfo, &pData, &lSize), h);
       
   464 
       
   465 							if (!bErrors)
       
   466 								if (!WriteBitmap(szBuffer, pFile, pInfo, pData, lSize))
       
   467 									bErrors = true;
       
   468 
       
   469 							m_Progress.StepIt();
       
   470 							UpdateWindow();
       
   471 						}
       
   472 					}
       
   473 				}
       
   474 
       
   475 				// decrement the iteration count
       
   476 				itoa(iMax - i - 1, szRemaining, 10);
       
   477 				m_Iterations.SetWindowText(szRemaining);
       
   478 				UpdateWindow();
       
   479 			}
       
   480 
       
   481 			// disconnect
       
   482 			Evaluate(Disconnect(h), h);
       
   483 			m_Progress.SetPos(100);
       
   484 			m_Iterations.SetWindowText(szPrevious);
       
   485 		}
       
   486 
       
   487 		if (m_ChkLogtofile.GetCheck())
       
   488 			CloseConnectionLogging();
       
   489 	}
       
   490 	else
       
   491 	{
       
   492 		// connect to loaded dll
       
   493 #if defined _DEBUG
       
   494 		HINSTANCE inst = LoadLibrary("statd.dll");
       
   495 #else // defined _DEBUG
       
   496 		HINSTANCE inst = LoadLibrary("stat.dll");
       
   497 #endif // defined _DEBUG
       
   498 		if (inst && LoadFunctionEntrypoints(inst))
       
   499 		{
       
   500 			// display version
       
   501 			MessageBox((*pfn_Version)(), "STAT DLL Version", MB_OK);
       
   502 
       
   503 			CWaitCursor oWait;
       
   504 
       
   505 			// log connections
       
   506 			if (m_ChkLogtofile.GetCheck())
       
   507 			{
       
   508 				if (0 != logFilePath.GetLength())
       
   509 				{
       
   510 					(*pfn_SetConnectionLogging)(logFilePath);
       
   511 				}
       
   512 			}
       
   513 
       
   514 			// get the connect string
       
   515 			switch(m_Connection.GetCurSel())
       
   516 			{
       
   517 			case 1:	// serial
       
   518 			case 2:	// infra-red
       
   519 			case 3:	// bluetooth
       
   520 			case 4:	// USB
       
   521 				m_Platform.GetLBText(m_Platform.GetCurSel(), szBuffer);
       
   522 				break;
       
   523 			
       
   524 			case 0:	// socket
       
   525 				m_Address.GetWindowText(szBuffer, sizeof(szBuffer));
       
   526 				break;
       
   527 			}
       
   528 
       
   529 			// connect
       
   530 			Evaluate(h = (*pfn_Connect)((STATCONNECTTYPE)(m_Connection.GetCurSel() + 1), szBuffer), h);
       
   531 
       
   532 			if (h)
       
   533 			{
       
   534 				m_Progress.StepIt();
       
   535 				UpdateWindow();
       
   536 
       
   537 				// log commands
       
   538 				if (m_ChkLogtofile.GetCheck())
       
   539 				{
       
   540 					if (0 != logFile.GetLength())
       
   541 						Evaluate((*pfn_SetCommandLogging)(h, logFile, NULL, EVerbose, true), h);
       
   542 				}
       
   543 
       
   544 				// set command delay
       
   545 				if (!bErrors)
       
   546 				{
       
   547 					m_Delay.GetWindowText(szBuffer, sizeof(szBuffer));
       
   548 					iValue = atoi(szBuffer);
       
   549 					Evaluate((*pfn_SetCommandDelay)(h, iValue), h);
       
   550 				}
       
   551 
       
   552 				// set image verification
       
   553 				if (!bErrors)
       
   554 				{
       
   555 					if (m_CheckVerification.GetCheck())
       
   556 					{
       
   557 						m_Fudge.GetWindowText(szBuffer, sizeof(szBuffer));
       
   558 						iValue = atoi(szBuffer);
       
   559 						m_RefDir.GetWindowText(szBuffer, sizeof(szBuffer));
       
   560 						if (*szBuffer)
       
   561 							Evaluate((*pfn_SetImageVerification)(h, szBuffer, m_RemoveImages.GetCheck()?true:false, iValue), h);
       
   562 					}
       
   563 				}
       
   564 
       
   565 				m_Iterations.GetWindowText(szPrevious, sizeof(szPrevious));
       
   566 				int iMax = atoi(szPrevious);
       
   567 				for (int i=0;i<iMax;i++)
       
   568 				{
       
   569 					if (!bErrors)
       
   570 					{
       
   571 						// execute raw command
       
   572 						if (m_CheckRawCmd.GetCheck())
       
   573 						{
       
   574 							m_RawCmd.GetWindowText(szBuffer, sizeof(szBuffer));
       
   575 							if (*szBuffer)
       
   576 							{
       
   577 								Evaluate((*pfn_SendRawCommand)(h, szBuffer), h);
       
   578 								m_Progress.StepIt();
       
   579 								UpdateWindow();
       
   580 							}
       
   581 						}
       
   582 					}
       
   583 
       
   584 					if (!bErrors)
       
   585 					{
       
   586 						// execute command file
       
   587 						if (m_CheckCmdFile.GetCheck())
       
   588 						{
       
   589 							m_CmdFile.GetWindowText(szBuffer, sizeof(szBuffer));
       
   590 							if (*szBuffer)
       
   591 							{
       
   592 								Evaluate((*pfn_SendCommandFile)(h, szBuffer), h);
       
   593 								m_Progress.StepIt();
       
   594 								UpdateWindow();
       
   595 							}
       
   596 						}
       
   597 					}
       
   598 
       
   599 					if (!bErrors)
       
   600 					{
       
   601 						// get a snapshot
       
   602 						if (m_CheckSnapshot.GetCheck())
       
   603 						{
       
   604 							m_Snapshot.GetWindowText(szBuffer, sizeof(szBuffer));
       
   605 							if (*szBuffer)
       
   606 							{
       
   607 								DeleteFile(szBuffer);
       
   608 								Evaluate((*pfn_GetSnapshot)(h, &pFile, &pInfo, &pData, &lSize), h);
       
   609 
       
   610 								if (!bErrors)
       
   611 									if (!WriteBitmap(szBuffer, pFile, pInfo, pData, lSize))
       
   612 										bErrors = true;
       
   613 
       
   614 								m_Progress.StepIt();
       
   615 								UpdateWindow();
       
   616 							}
       
   617 						}
       
   618 					}
       
   619 
       
   620 					// decrement the iteration count
       
   621 					itoa(iMax - i - 1, szRemaining, 10);
       
   622 					m_Iterations.SetWindowText(szRemaining);
       
   623 					UpdateWindow();
       
   624 				}
       
   625 
       
   626 				// disconnect
       
   627 				Evaluate((*pfn_Disconnect)(h), h); // start of list
       
   628 				m_Progress.SetPos(100);
       
   629 				m_Iterations.SetWindowText(szPrevious);
       
   630 			}
       
   631 
       
   632 			// close logging
       
   633 			if (m_ChkLogtofile.GetCheck())
       
   634 				if (pfn_CloseConnectionLogging)	// doesn't exist in 3.2
       
   635 					(*pfn_CloseConnectionLogging)();
       
   636 		}
       
   637 		else
       
   638 			MessageBox("STAT.DLL could not be loaded successfully", NULL, MB_OK|MB_ICONERROR);
       
   639 
       
   640 		// finished
       
   641 		if (inst)
       
   642 			FreeLibrary(inst);
       
   643 	}
       
   644 
       
   645 	if (m_ChkLogtofile.GetCheck() && (0 != logFile.GetLength()))
       
   646 	{
       
   647 		if ((bErrors && (IDYES == AfxMessageBox("Do you wish to view the log file?", MB_YESNO | MB_ICONINFORMATION | MB_DEFBUTTON1))) ||
       
   648 			(!bErrors && (IDYES == AfxMessageBox("All tests completed successfully.  Do you wish to view the log file?", MB_YESNO | MB_ICONINFORMATION | MB_DEFBUTTON2))))
       
   649 		{
       
   650 			CString logFileDirectory;
       
   651 			GetLogFolder(logFileDirectory);
       
   652 			::ShellExecute(GetSafeHwnd(), NULL, logFile, NULL, 
       
   653 				logFileDirectory, SW_SHOW);
       
   654 		}
       
   655 	}
       
   656 	else
       
   657 	{
       
   658 		if (!bErrors)
       
   659 			AfxMessageBox("All tests completed successfully.", MB_OK | MB_ICONINFORMATION);
       
   660 	}
       
   661 }
       
   662 
       
   663 //////////////////////////////////////////////////////////////////////////////////////
       
   664 
       
   665 int CDlltestDlg::GetIncrement()
       
   666 {
       
   667 	int increment = 0;
       
   668 
       
   669 	if (m_CheckRawCmd.GetCheck())
       
   670 		increment++;
       
   671 
       
   672 	if (m_CheckCmdFile.GetCheck())
       
   673 		increment++;
       
   674 
       
   675 	if (m_CheckSnapshot.GetCheck())
       
   676 		increment++;
       
   677 
       
   678 	m_Iterations.GetWindowText(szBuffer, sizeof(szBuffer));
       
   679 	int iMax = atoi(szBuffer);
       
   680 	if (iMax)
       
   681 		increment *= iMax;
       
   682 
       
   683 	// for Connect()/Disconnect()
       
   684 	increment++;
       
   685 
       
   686 	return (int) 100 / increment;
       
   687 }
       
   688 
       
   689 //////////////////////////////////////////////////////////////////////////////////////
       
   690 
       
   691 void CDlltestDlg::LoadEntrypoint(HINSTANCE inst, FARPROC *fn, const char *name)
       
   692 {
       
   693 	if (!*fn)
       
   694 		*fn = GetProcAddress(inst, name);
       
   695 }
       
   696 
       
   697 //////////////////////////////////////////////////////////////////////////////////////
       
   698 
       
   699 bool CDlltestDlg::LoadFunctionEntrypoints(HINSTANCE inst)
       
   700 {
       
   701 	// get
       
   702 	LoadEntrypoint(inst, (FARPROC *)&pfn_Version, "Version");
       
   703 	LoadEntrypoint(inst, (FARPROC *)&pfn_GetError, "GetError");
       
   704 	LoadEntrypoint(inst, (FARPROC *)&pfn_SetConnectionLogging, "SetConnectionLogging");
       
   705 	LoadEntrypoint(inst, (FARPROC *)&pfn_CloseConnectionLogging, "CloseConnectionLogging");
       
   706 	LoadEntrypoint(inst, (FARPROC *)&pfn_Connect, "Connect");
       
   707 	LoadEntrypoint(inst, (FARPROC *)&pfn_Disconnect, "Disconnect");
       
   708 	LoadEntrypoint(inst, (FARPROC *)&pfn_SetCommandDelay, "SetCommandDelay");
       
   709 	LoadEntrypoint(inst, (FARPROC *)&pfn_SetCommandLogging, "SetCommandLogging");
       
   710 	LoadEntrypoint(inst, (FARPROC *)&pfn_SetImageVerification, "SetImageVerification");
       
   711 	LoadEntrypoint(inst, (FARPROC *)&pfn_SendRawCommand, "SendRawCommand");
       
   712 	LoadEntrypoint(inst, (FARPROC *)&pfn_SendCommandFile, "SendCommandFile");
       
   713 	LoadEntrypoint(inst, (FARPROC *)&pfn_GetSnapshot, "GetSnapshot");
       
   714 
       
   715 
       
   716 	// check
       
   717 	if (pfn_Version && pfn_GetError && pfn_SetConnectionLogging && pfn_Connect && pfn_Disconnect &&
       
   718 		pfn_SetCommandDelay && pfn_SetCommandLogging && pfn_GetSnapshot && pfn_CloseConnectionLogging &&
       
   719 		pfn_SetImageVerification && pfn_SendRawCommand && pfn_SendCommandFile )
       
   720 	{
       
   721 		return true;
       
   722 	}
       
   723 
       
   724 	MessageBox("Not all required STAT entrypoints could be located.  This application is compatible with STAT DLL 3.3 (September 2002) and later.", NULL, MB_OK|MB_ICONERROR);
       
   725 	return false;
       
   726 }
       
   727 
       
   728 //////////////////////////////////////////////////////////////////////////////////////
       
   729 
       
   730 void CDlltestDlg::Evaluate(int ret, int handle)
       
   731 {
       
   732 	if (!ret)
       
   733 	{
       
   734 		if (m_Link.GetCurSel() == 1)
       
   735 			strcpy(szBuffer, GetError(handle));
       
   736 		else
       
   737 			strcpy(szBuffer, pfn_GetError(handle));
       
   738 
       
   739 		bErrors = true;
       
   740 		MessageBox(szBuffer, NULL, MB_OK|MB_ICONERROR);
       
   741 	}
       
   742 }
       
   743 
       
   744 //////////////////////////////////////////////////////////////////////////////////////
       
   745 
       
   746 bool CDlltestDlg::WriteBitmap(char *file, TBitmapFileHeader *fileheader, TBitmapInfoHeader * bmpHeader, char *bmpBits, unsigned long lSize)
       
   747 {
       
   748 	bool success = false;
       
   749 
       
   750 	// write the whole lot out to file
       
   751 	HANDLE infile;
       
   752 	if (INVALID_HANDLE_VALUE != (infile = CreateFile(file,
       
   753 										   GENERIC_WRITE,
       
   754 										   0, 
       
   755 										   NULL, 
       
   756 										   CREATE_ALWAYS,
       
   757 										   FILE_ATTRIBUTE_NORMAL,
       
   758 										   0)))
       
   759 	{
       
   760 		DWORD dwBytesWritten = 0;
       
   761 
       
   762 		// write the file info
       
   763 		if (WriteFile(infile, (LPVOID *)fileheader, sizeof(TBitmapFileHeader), &dwBytesWritten, NULL) &&
       
   764 			dwBytesWritten == sizeof(TBitmapFileHeader))
       
   765 		{
       
   766 			// write the bitmap info
       
   767 			if (WriteFile(infile, (LPVOID *)bmpHeader, sizeof(TBitmapInfoHeader), &dwBytesWritten, NULL) &&
       
   768 				dwBytesWritten == sizeof(TBitmapInfoHeader))
       
   769 			{
       
   770 				// write the bitmap data
       
   771 				if (WriteFile(infile, (LPVOID *)bmpBits, lSize, &dwBytesWritten, NULL) &&
       
   772 					dwBytesWritten == lSize)
       
   773 				{
       
   774 					success = true;
       
   775 				}
       
   776 			}
       
   777 		}
       
   778 
       
   779 		CloseHandle(infile);
       
   780 	}
       
   781 
       
   782 	return success;
       
   783 }
       
   784 
       
   785 //////////////////////////////////////////////////////////////////////////////////////
       
   786 
       
   787 void CDlltestDlg::OnChangeConnection() 
       
   788 {
       
   789 	ChangeConnection(0);
       
   790 }
       
   791 
       
   792 //////////////////////////////////////////////////////////////////////////////////////
       
   793 
       
   794 void CDlltestDlg::ChangeConnection(int iSelection) 
       
   795 {
       
   796 	switch(m_Connection.GetCurSel())
       
   797 	{
       
   798 	case 0:	// socket
       
   799 		m_Address.EnableWindow();
       
   800 		m_Platform.EnableWindow(FALSE);
       
   801 		break;
       
   802 	
       
   803 	case 1:	// serial
       
   804 	case 2:	// infra-red
       
   805 	case 3:	// bluetooth
       
   806 	case 4:	// USB
       
   807 		m_Platform.ResetContent();
       
   808 		m_Platform.AddString("COM1");
       
   809 		m_Platform.AddString("COM2");
       
   810 		m_Platform.AddString("COM3");
       
   811 		m_Platform.AddString("COM4");
       
   812 		m_Platform.AddString("COM5");
       
   813 		m_Platform.AddString("COM6");
       
   814 		m_Platform.AddString("COM7");
       
   815 		m_Platform.SetCurSel(iSelection);
       
   816 		m_Platform.EnableWindow(TRUE);
       
   817 		m_Address.EnableWindow(FALSE);
       
   818 		break;
       
   819 	}
       
   820 }
       
   821 
       
   822 //////////////////////////////////////////////////////////////////////////////////////
       
   823 
       
   824 void CDlltestDlg::SaveSettings()
       
   825 {
       
   826 	(*szBuffer) = (char)0;
       
   827 	m_Iterations.GetWindowText(szBuffer, sizeof(szBuffer));
       
   828 	statIniFile.WriteKey(szBuffer,ST_ITERATIONS,ST_TEST_KEY);
       
   829 
       
   830 	(*szBuffer) = (char)0;
       
   831 	m_Delay.GetWindowText(szBuffer, sizeof(szBuffer));
       
   832 	statIniFile.WriteKey(szBuffer,ST_DELAY,ST_TEST_KEY);
       
   833 
       
   834 	(*szBuffer) = (char)0;
       
   835 	m_LogFile.GetWindowText(szBuffer, sizeof(szBuffer));
       
   836 	statIniFile.WriteKey(szBuffer,ST_LOGFILE,ST_TEST_KEY);
       
   837 
       
   838 	(*szBuffer) = (char)0;
       
   839 	m_CmdFile.GetWindowText(szBuffer, sizeof(szBuffer));
       
   840 	statIniFile.WriteKey(szBuffer,ST_CMDFILE,ST_TEST_KEY);
       
   841 
       
   842 	(*szBuffer) = (char)0;
       
   843 	m_RawCmd.GetWindowText(szBuffer, sizeof(szBuffer));
       
   844 	statIniFile.WriteKey(szBuffer,ST_RAWCMD,ST_TEST_KEY);
       
   845 
       
   846 	(*szBuffer) = (char)0;
       
   847 	m_Fudge.GetWindowText(szBuffer, sizeof(szBuffer));
       
   848 	statIniFile.WriteKey(szBuffer,ST_FUDGE,ST_TEST_KEY);
       
   849 
       
   850 	(*szBuffer) = (char)0;
       
   851 	m_Snapshot.GetWindowText(szBuffer, sizeof(szBuffer));
       
   852 	statIniFile.WriteKey(szBuffer,ST_SNAPSHOT,ST_TEST_KEY);
       
   853 
       
   854 
       
   855 	(*szBuffer) = (char)0;
       
   856 	m_RefDir.GetWindowText(szBuffer, sizeof(szBuffer));
       
   857 	statIniFile.WriteKey(szBuffer,ST_REFDIR,ST_TEST_KEY);
       
   858 
       
   859 	(*szBuffer) = (char)0;
       
   860 	m_Address.GetWindowText(szBuffer, sizeof(szBuffer));
       
   861 	statIniFile.WriteKey(szBuffer,ST_ADDRESS,ST_TEST_KEY);
       
   862 
       
   863 	_ltot( m_Link.GetCurSel(), szBuffer, 10);
       
   864 	statIniFile.WriteKey(szBuffer,ST_LINK,ST_TEST_KEY);
       
   865 
       
   866 	_ltot( m_Connection.GetCurSel(), szBuffer, 10);
       
   867 	statIniFile.WriteKey(szBuffer,ST_CONNECTIONDLL,ST_TEST_KEY);
       
   868 
       
   869 	_ltot( m_Platform.GetCurSel(), szBuffer, 10);
       
   870 	statIniFile.WriteKey(szBuffer,ST_PLATFORM,ST_TEST_KEY);
       
   871 
       
   872 	_ltot( m_CheckRawCmd.GetCheck(), szBuffer, 10);
       
   873 	statIniFile.WriteKey(szBuffer,ST_CHKRAWCMD,ST_TEST_KEY);
       
   874 
       
   875 	_ltot( m_CheckCmdFile.GetCheck(), szBuffer, 10);
       
   876 	statIniFile.WriteKey(szBuffer,ST_CHKCMDFILE,ST_TEST_KEY);
       
   877 
       
   878 	_ltot( m_CheckVerification.GetCheck(), szBuffer, 10);
       
   879 	statIniFile.WriteKey(szBuffer,ST_CHKVERIF,ST_TEST_KEY);
       
   880 
       
   881 	_ltot( m_RemoveImages.GetCheck(), szBuffer, 10);
       
   882 	statIniFile.WriteKey(szBuffer,ST_VERIFYREMOVEIMAGES,ST_TEST_KEY);
       
   883 
       
   884 	_ltot( m_CheckSnapshot.GetCheck(), szBuffer, 10);
       
   885 	statIniFile.WriteKey(szBuffer,ST_CHKSNAP,ST_TEST_KEY);
       
   886 
       
   887 	_ltot( m_ChkLogtofile.GetCheck(), szBuffer, 10);
       
   888 	statIniFile.WriteKey(szBuffer,ST_CHKLOGTOFILE,ST_TEST_KEY);
       
   889 }
       
   890 
       
   891 //////////////////////////////////////////////////////////////////////////////////////
       
   892 
       
   893 void CDlltestDlg::ReadSettings()
       
   894 {
       
   895 	long lCount = 0;
       
   896 	statIniFile.SetIniFileName(STAT_INI_NAME);
       
   897 	*(szBuffer) = (char)0;
       
   898 	if(statIniFile.SectionExists(ST_TEST_KEY) )
       
   899 	{
       
   900 		CString setting;
       
   901 		setting.Empty();
       
   902 		setting=statIniFile.GetKeyValue(ST_ITERATIONS,ST_TEST_KEY);
       
   903 		if(!setting.IsEmpty())
       
   904 		{
       
   905 			if (_ttoi(setting)<1)
       
   906 				setting=_T("1");
       
   907 
       
   908 			m_Iterations.SetWindowText(setting);
       
   909 		}
       
   910 
       
   911 
       
   912 		setting=statIniFile.GetKeyValue(ST_DELAY,ST_TEST_KEY);
       
   913 		if(!setting.IsEmpty())
       
   914 		{
       
   915 			int iPos = _ttoi(setting);
       
   916 			if (iPos < 100)
       
   917 				setting= _T("100");
       
   918 
       
   919 			if (iPos > 30000)
       
   920 				setting= _T("30000");
       
   921 
       
   922 			m_Delay.SetWindowText(setting);
       
   923 		}
       
   924 
       
   925 	// logging settings
       
   926 		setting.Empty();
       
   927 		setting=statIniFile.GetKeyValue(ST_LOGFILE,ST_TEST_KEY);
       
   928 		if(!setting.IsEmpty())
       
   929 		{
       
   930 			m_LogFile.SetWindowText(setting);
       
   931 		}
       
   932 
       
   933 		setting.Empty();
       
   934 		lCount=0;
       
   935 		setting=statIniFile.GetKeyValue(ST_CHKLOGTOFILE,ST_TEST_KEY);
       
   936 		if(!setting.IsEmpty())
       
   937 		{
       
   938 			lCount = _ttoi(setting);
       
   939 			m_ChkLogtofile.SetCheck(lCount);
       
   940 		}
       
   941 
       
   942 
       
   943 
       
   944 	// command file settings
       
   945 		setting.Empty();
       
   946 		setting=statIniFile.GetKeyValue(ST_CMDFILE,ST_TEST_KEY);
       
   947 		if(!setting.IsEmpty())
       
   948 		{
       
   949 			m_CmdFile.SetWindowText(setting);
       
   950 		}
       
   951 
       
   952 		setting.Empty();
       
   953 		lCount=0;
       
   954 		setting=statIniFile.GetKeyValue(ST_CHKCMDFILE,ST_TEST_KEY);
       
   955 		if(!setting.IsEmpty())
       
   956 		{
       
   957 			lCount = _ttoi(setting);
       
   958 			m_CheckCmdFile.SetCheck(lCount);
       
   959 		}
       
   960 
       
   961 	// raw command settings
       
   962 		setting.Empty();
       
   963 		setting=statIniFile.GetKeyValue(ST_RAWCMD,ST_TEST_KEY);
       
   964 		if(!setting.IsEmpty())
       
   965 		{
       
   966 			m_RawCmd.SetWindowText(setting);
       
   967 		}
       
   968 		setting.Empty();
       
   969 		lCount=0;
       
   970 		setting=statIniFile.GetKeyValue(ST_CHKRAWCMD,ST_TEST_KEY);
       
   971 		if(!setting.IsEmpty())
       
   972 		{
       
   973 			lCount=_ttol(setting);
       
   974 			m_CheckRawCmd.SetCheck(lCount);
       
   975 		}
       
   976 
       
   977 
       
   978 	// snapshot settings
       
   979 		setting.Empty();
       
   980 		setting=statIniFile.GetKeyValue(ST_SNAPSHOT,ST_TEST_KEY);
       
   981 		if(!setting.IsEmpty())
       
   982 		{
       
   983 			m_Snapshot.SetWindowText(setting);
       
   984 		}
       
   985 		setting.Empty();
       
   986 		lCount=0;
       
   987 		setting=statIniFile.GetKeyValue(ST_CHKSNAP,ST_TEST_KEY);
       
   988 		if(!setting.IsEmpty())
       
   989 		{
       
   990 			lCount=_ttol(setting);
       
   991 			m_CheckSnapshot.SetCheck(lCount);
       
   992 		}
       
   993 
       
   994 
       
   995 	// image verification settings
       
   996 		setting.Empty();
       
   997 		setting=statIniFile.GetKeyValue(ST_FUDGE,ST_TEST_KEY);
       
   998 		if(!setting.IsEmpty())
       
   999 			m_Fudge.SetWindowText(setting);
       
  1000 
       
  1001 		setting.Empty();
       
  1002 		setting=statIniFile.GetKeyValue(ST_REFDIR,ST_TEST_KEY);
       
  1003 		if(!setting.IsEmpty())
       
  1004 			m_RefDir.SetWindowText(setting);
       
  1005 		setting.Empty();
       
  1006 		lCount=0;
       
  1007 		setting=statIniFile.GetKeyValue(ST_CHKVERIF,ST_TEST_KEY);
       
  1008 		if(!setting.IsEmpty())
       
  1009 		{
       
  1010 			lCount=_ttol(setting);
       
  1011 			m_CheckVerification.SetCheck(lCount);
       
  1012 		}
       
  1013 
       
  1014 		setting.Empty();
       
  1015 		setting=statIniFile.GetKeyValue(ST_VERIFYREMOVEIMAGES,ST_TEST_KEY);
       
  1016 		if(!setting.IsEmpty())
       
  1017 		{
       
  1018 			m_RemoveImages.SetWindowText(setting);
       
  1019 		}
       
  1020 		setting.Empty();
       
  1021 		lCount=0;
       
  1022 		setting=statIniFile.GetKeyValue(ST_VERIFYREMOVEIMAGES,ST_TEST_KEY);
       
  1023 		if(!setting.IsEmpty())
       
  1024 		{
       
  1025 			lCount=_ttol(setting);
       
  1026 			m_RemoveImages.SetCheck(lCount);
       
  1027 		}
       
  1028 
       
  1029 
       
  1030 	// connection settings
       
  1031 		setting.Empty();
       
  1032 		lCount=0;
       
  1033 		setting=statIniFile.GetKeyValue(ST_LINK,ST_TEST_KEY);
       
  1034 		if(!setting.IsEmpty())
       
  1035 		{
       
  1036 			lCount=_ttol(setting);
       
  1037 			m_Link.SetCurSel(lCount);
       
  1038 		}
       
  1039 		setting.Empty();
       
  1040 		lCount=0;
       
  1041 		setting=statIniFile.GetKeyValue(ST_CONNECTIONDLL,ST_TEST_KEY);
       
  1042 		if(!setting.IsEmpty())
       
  1043 		{
       
  1044 			lCount=_ttol(setting);
       
  1045 			m_Connection.SetCurSel(lCount);
       
  1046 		}
       
  1047 		setting.Empty();
       
  1048 		lCount=0;
       
  1049 		setting=statIniFile.GetKeyValue(ST_PLATFORM,ST_TEST_KEY);
       
  1050 		if(!setting.IsEmpty())
       
  1051 		{
       
  1052 			lCount=_ttol(setting);
       
  1053 			ChangeConnection(lCount);
       
  1054 		}
       
  1055 		else
       
  1056 			ChangeConnection(0);
       
  1057 		
       
  1058 		setting.Empty();
       
  1059 		setting=statIniFile.GetKeyValue(ST_ADDRESS,ST_TEST_KEY);
       
  1060 		if(!setting.IsEmpty())
       
  1061 		{
       
  1062 			m_Address.SetWindowText(setting);
       
  1063 		}
       
  1064 	}
       
  1065 	// enable/disable accordingly
       
  1066 	OnCheckcmdfile();
       
  1067 	OnCheckrawcmd();
       
  1068 	OnChecksnapshot();
       
  1069 	OnCheckverification();
       
  1070 
       
  1071 	bRunning = false;
       
  1072 
       
  1073 	UpdateWindow();
       
  1074 }
       
  1075 
       
  1076 //////////////////////////////////////////////////////////////////////////////////////
       
  1077 
       
  1078 void CDlltestDlg::OnOK() 
       
  1079 {
       
  1080 	CWaitCursor oWait;
       
  1081 	SaveSettings();
       
  1082 	CDialog::OnOK();
       
  1083 }
       
  1084 
       
  1085 //////////////////////////////////////////////////////////////////////////////////////
       
  1086 
       
  1087 void CDlltestDlg::OnResetsettings() 
       
  1088 {
       
  1089 
       
  1090 	GetDlgItem(IDC_LOGFILE)->SetWindowText("statdllv4cdecltest.log");
       
  1091 	m_ChkLogtofile.SetCheck(TRUE);
       
  1092 	OnChklogtofile();
       
  1093 
       
  1094 	GetDlgItem(IDC_ADDRESS)->SetWindowText("");
       
  1095 	GetDlgItem(IDC_DELAY)->SetWindowText("100");
       
  1096 	GetDlgItem(IDC_ITERATIONS)->SetWindowText("1");
       
  1097 	m_Link.SetCurSel(0);
       
  1098 	m_Connection.SetCurSel(0);
       
  1099 	ChangeConnection(0);
       
  1100 
       
  1101 	UpdateWindow();
       
  1102 }
       
  1103 
       
  1104 //////////////////////////////////////////////////////////////////////////////////////
       
  1105 
       
  1106 void CDlltestDlg::OnResettests() 
       
  1107 {
       
  1108 	// set some default values
       
  1109 
       
  1110 	GetDlgItem(IDC_CMDFILE)->SetWindowText("statdllv4test.txt");
       
  1111 
       
  1112 	// tests
       
  1113 	GetDlgItem(IDC_ITERATIONS)->SetWindowText("1");
       
  1114 	GetDlgItem(IDC_RAWCMD)->SetWindowText("<B><S><E>");
       
  1115 	GetDlgItem(IDC_REFDIR)->SetWindowText("refimages");
       
  1116 	GetDlgItem(IDC_FUDGE)->SetWindowText("20");
       
  1117 	GetDlgItem(IDC_SNAPSHOT)->SetWindowText("mysnapshot.bmp");
       
  1118 
       
  1119 	m_CheckCmdFile.SetCheck(TRUE);
       
  1120 	m_CheckVerification.SetCheck(TRUE);
       
  1121 	m_RemoveImages.SetCheck(TRUE);
       
  1122 	m_CheckSnapshot.SetCheck(TRUE);
       
  1123 	m_CheckRawCmd.SetCheck(TRUE);
       
  1124 	OnCheckcmdfile();
       
  1125 	OnCheckrawcmd();
       
  1126 	OnChecksnapshot();
       
  1127 	OnCheckverification();
       
  1128 
       
  1129 	UpdateWindow();
       
  1130 }
       
  1131 
       
  1132 //////////////////////////////////////////////////////////////////////////////////////
       
  1133 
       
  1134 void CDlltestDlg::OnBrowselog() 
       
  1135 {
       
  1136 	// use the folder of the current script as a starting point
       
  1137 	m_LogFile.GetWindowText(szBuffer, sizeof(szBuffer));
       
  1138 	CString buf = szBuffer;
       
  1139 	if (!buf.IsEmpty())
       
  1140 	{
       
  1141 		int index = buf.ReverseFind('\\');
       
  1142 		if (index != -1)
       
  1143 		{
       
  1144 			CString folder = buf.Left(index);
       
  1145 			SetCurrentDirectory(folder.GetBuffer(0));
       
  1146 		}
       
  1147 	}
       
  1148 
       
  1149 	CFileDialog dlgStatFileOpen(TRUE, 
       
  1150 								NULL, 
       
  1151 								NULL, 
       
  1152 								OFN_PATHMUSTEXIST, 
       
  1153 								_T("Log Files (*.log)|*.log|All Files (*.*)|*.*||"));
       
  1154 
       
  1155 	// new script file to use
       
  1156 	if (dlgStatFileOpen.DoModal() == IDOK)	//when ok is pressed
       
  1157 		m_LogFile.SetWindowText(dlgStatFileOpen.GetPathName());
       
  1158 }
       
  1159 
       
  1160 //////////////////////////////////////////////////////////////////////////////////////
       
  1161 
       
  1162 void CDlltestDlg::OnChklogtofile() 
       
  1163 {
       
  1164 	if (m_ChkLogtofile.GetCheck())
       
  1165 	{
       
  1166 		m_LogFile.EnableWindow(TRUE);
       
  1167 		m_BrowseLog.EnableWindow(TRUE);
       
  1168 	}
       
  1169 	else
       
  1170 	{
       
  1171 		m_LogFile.EnableWindow(FALSE);
       
  1172 		m_BrowseLog.EnableWindow(FALSE);
       
  1173 	}
       
  1174 }
       
  1175 
       
  1176 //////////////////////////////////////////////////////////////////////////////////////
       
  1177 
       
  1178 void CDlltestDlg::OnCheckcmdfile() 
       
  1179 {
       
  1180 	if (m_CheckCmdFile.GetCheck())
       
  1181 	{
       
  1182 		m_CmdFile.EnableWindow(TRUE);
       
  1183 		m_BrowseCmdFile.EnableWindow(TRUE);
       
  1184 	}
       
  1185 	else
       
  1186 	{
       
  1187 		m_CmdFile.EnableWindow(FALSE);
       
  1188 		m_BrowseCmdFile.EnableWindow(FALSE);
       
  1189 	}
       
  1190 }
       
  1191 
       
  1192 //////////////////////////////////////////////////////////////////////////////////////
       
  1193 
       
  1194 void CDlltestDlg::OnCheckrawcmd() 
       
  1195 {
       
  1196 	if (m_CheckRawCmd.GetCheck())
       
  1197 	{
       
  1198 		m_RawCmd.EnableWindow(TRUE);
       
  1199 	}
       
  1200 	else
       
  1201 	{
       
  1202 		m_RawCmd.EnableWindow(FALSE);
       
  1203 	}
       
  1204 }
       
  1205 
       
  1206 //////////////////////////////////////////////////////////////////////////////////////
       
  1207 
       
  1208 void CDlltestDlg::OnChecksnapshot() 
       
  1209 {
       
  1210 	if (m_CheckSnapshot.GetCheck())
       
  1211 	{
       
  1212 		m_Snapshot.EnableWindow(TRUE);
       
  1213 		m_BrowseSnapshot.EnableWindow(TRUE);
       
  1214 	}
       
  1215 	else
       
  1216 	{
       
  1217 		m_Snapshot.EnableWindow(FALSE);
       
  1218 		m_BrowseSnapshot.EnableWindow(FALSE);
       
  1219 	}
       
  1220 }
       
  1221 
       
  1222 //////////////////////////////////////////////////////////////////////////////////////
       
  1223 
       
  1224 void CDlltestDlg::OnCheckverification() 
       
  1225 {
       
  1226 	if (m_CheckVerification.GetCheck())
       
  1227 	{
       
  1228 		m_RefDir.EnableWindow(TRUE);
       
  1229 		m_Fudge.EnableWindow(TRUE);
       
  1230 		m_BrowseRefImages.EnableWindow(TRUE);
       
  1231 		m_RemoveImages.EnableWindow(TRUE);
       
  1232 	}
       
  1233 	else
       
  1234 	{
       
  1235 		m_RefDir.EnableWindow(FALSE);
       
  1236 		m_Fudge.EnableWindow(FALSE);
       
  1237 		m_BrowseRefImages.EnableWindow(FALSE);
       
  1238 		m_RemoveImages.EnableWindow(FALSE);
       
  1239 	}
       
  1240 }
       
  1241 
       
  1242 //////////////////////////////////////////////////////////////////////////////////////
       
  1243 
       
  1244 void CDlltestDlg::OnBrowsecmdfile() 
       
  1245 {
       
  1246 	// use the folder of the current script as a starting point
       
  1247 	m_CmdFile.GetWindowText(szBuffer, sizeof(szBuffer));
       
  1248 	CString buf = szBuffer;
       
  1249 	if (!buf.IsEmpty())
       
  1250 	{
       
  1251 		int index = buf.ReverseFind('\\');
       
  1252 		if (index != -1)
       
  1253 		{
       
  1254 			CString folder = buf.Left(index);
       
  1255 			SetCurrentDirectory(folder.GetBuffer(0));
       
  1256 		}
       
  1257 	}
       
  1258 
       
  1259 	CFileDialog dlgStatFileOpen(TRUE, 
       
  1260 								NULL, 
       
  1261 								NULL, 
       
  1262 								OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, 
       
  1263 								_T("Script Files (*.txt)|*.txt|All Files (*.*)|*.*||"));
       
  1264 
       
  1265 	// new script file to use
       
  1266 	if (dlgStatFileOpen.DoModal() == IDOK)	//when ok is pressed
       
  1267 		m_CmdFile.SetWindowText(dlgStatFileOpen.GetPathName());
       
  1268 }
       
  1269 
       
  1270 //////////////////////////////////////////////////////////////////////////////////////
       
  1271 
       
  1272 void CDlltestDlg::OnBrowsesnapshot() 
       
  1273 {
       
  1274 	// use the folder of the current script as a starting point
       
  1275 	m_Snapshot.GetWindowText(szBuffer, sizeof(szBuffer));
       
  1276 	CString buf = szBuffer;
       
  1277 	if (!buf.IsEmpty())
       
  1278 	{
       
  1279 		int index = buf.ReverseFind('\\');
       
  1280 		if (index != -1)
       
  1281 		{
       
  1282 			CString folder = buf.Left(index);
       
  1283 			SetCurrentDirectory(folder.GetBuffer(0));
       
  1284 		}
       
  1285 	}
       
  1286 
       
  1287 	CFileDialog dlgStatFileOpen(TRUE, 
       
  1288 								NULL, 
       
  1289 								NULL, 
       
  1290 								OFN_PATHMUSTEXIST,
       
  1291 								_T("Bitmap Files (*.bmp)|*.txt|All Files (*.*)|*.*||"));
       
  1292 
       
  1293 	// new script file to use
       
  1294 	if (dlgStatFileOpen.DoModal() == IDOK)	//when ok is pressed
       
  1295 		m_Snapshot.SetWindowText(dlgStatFileOpen.GetPathName());
       
  1296 }
       
  1297 
       
  1298 //////////////////////////////////////////////////////////////////////////////////////
       
  1299 
       
  1300 void CDlltestDlg::OnBrowserefimages() 
       
  1301 {
       
  1302 	TCHAR chName[MAX_PATH];
       
  1303 
       
  1304 	BROWSEINFO bi = {0};
       
  1305 	bi.hwndOwner = m_hWnd;
       
  1306 	bi.lpszTitle = _T("Please select folder where the reference bitmap files are stored...");
       
  1307 
       
  1308 	LPITEMIDLIST lpIDList = ::SHBrowseForFolder(&bi); //now display dialog box 
       
  1309 
       
  1310 	::SHGetPathFromIDList(lpIDList, chName); //Converts an item identifier list to a file system path
       
  1311 
       
  1312 	m_RefDir.SetWindowText(chName);	//pastes location into edit box
       
  1313 }
       
  1314 
       
  1315 
       
  1316 //////////////////////////////////////////////////////////////////////////////////////
       
  1317 // Set up image verification
       
  1318 void CDlltestDlg::EnableFields(bool bEnable)
       
  1319 {
       
  1320 	GetDlgItem(IDC_LINK)->EnableWindow(bEnable);
       
  1321 	GetDlgItem(IDC_DELAY)->EnableWindow(bEnable);
       
  1322 //	GetDlgItem(IDC_ITERATIONS)->EnableWindow(bEnable);
       
  1323 	GetDlgItem(IDC_RESETSETTINGS)->EnableWindow(bEnable);
       
  1324 	GetDlgItem(IDC_CONNECTION)->EnableWindow(bEnable);
       
  1325 	GetDlgItem(IDC_PLATFORM)->EnableWindow(bEnable);
       
  1326 	GetDlgItem(IDC_ADDRESS)->EnableWindow(bEnable);
       
  1327 	GetDlgItem(IDC_CHKLOGTOFILE)->EnableWindow(bEnable);
       
  1328 	GetDlgItem(IDC_LOGFILE)->EnableWindow(bEnable);
       
  1329 	GetDlgItem(IDC_BROWSELOG)->EnableWindow(bEnable);
       
  1330 
       
  1331 	GetDlgItem(IDC_CHECKRAWCMD)->EnableWindow(bEnable);
       
  1332 	GetDlgItem(IDC_RAWCMD)->EnableWindow(bEnable);
       
  1333 	GetDlgItem(IDC_CHECKCMDFILE)->EnableWindow(bEnable);
       
  1334 	GetDlgItem(IDC_CMDFILE)->EnableWindow(bEnable);
       
  1335 	GetDlgItem(IDC_BROWSECMDFILE)->EnableWindow(bEnable);
       
  1336 	GetDlgItem(IDC_CHECKSNAPSHOT)->EnableWindow(bEnable);
       
  1337 	GetDlgItem(IDC_SNAPSHOT)->EnableWindow(bEnable);
       
  1338 	GetDlgItem(IDC_BROWSESNAPSHOT)->EnableWindow(bEnable);
       
  1339 	GetDlgItem(IDC_CHECKVERIFICATION)->EnableWindow(bEnable);
       
  1340 	GetDlgItem(IDC_OVERWRITE)->EnableWindow(bEnable);
       
  1341 	GetDlgItem(IDC_REFDIR)->EnableWindow(bEnable);
       
  1342 	GetDlgItem(IDC_BROWSEREFIMAGES)->EnableWindow(bEnable);
       
  1343 	GetDlgItem(IDC_FUDGE)->EnableWindow(bEnable);
       
  1344 	GetDlgItem(IDC_RESETTESTS)->EnableWindow(bEnable);
       
  1345 
       
  1346 	if (bEnable)
       
  1347 	{
       
  1348 		OnChklogtofile();
       
  1349 		OnCheckcmdfile();
       
  1350 		OnCheckrawcmd();
       
  1351 		OnChecksnapshot();
       
  1352 		OnCheckverification();
       
  1353 
       
  1354 		m_Run.SetWindowText(_T("Run"));
       
  1355 		bRunning = false;
       
  1356 	}
       
  1357 	else
       
  1358 	{
       
  1359 		m_Run.SetWindowText(_T("Stop"));
       
  1360 		bRunning = true;
       
  1361 	}
       
  1362 
       
  1363 	UpdateWindow();
       
  1364 }
       
  1365 
       
  1366 void CDlltestDlg::GetLogFolder(CString& logFileFolder) const
       
  1367 {
       
  1368 	// Get the log file folder location.
       
  1369 	// If this is specified in the 'ini' file then we
       
  1370 	// use the specified location.
       
  1371 	// if it is not specified in the 'ini' file then we
       
  1372 	// use a default value.
       
  1373 
       
  1374 	logFileFolder.Empty();
       
  1375 
       
  1376 	if(statIniFile.SectionExists(ST_TEST_KEY))
       
  1377 	{
       
  1378 		CString setting;
       
  1379 		setting.Empty();
       
  1380 		setting=statIniFile.GetKeyValue(ST_LOGFILEPATH,ST_TEST_KEY);
       
  1381 		if(!setting.IsEmpty())
       
  1382 			logFileFolder = setting;
       
  1383 	}
       
  1384 
       
  1385 	if(logFileFolder.IsEmpty())
       
  1386 	{
       
  1387 		logFileFolder = STAT_LOGFILEPATH_VALUE;
       
  1388 	}
       
  1389 }
       
  1390 
       
  1391 void CDlltestDlg::GetLogFilePath(const char* logFileName, CString& logFilePath) const
       
  1392 {
       
  1393 	// There are a mixture of method calls in this window
       
  1394 	// that specify logging.
       
  1395 	// Also, in this window we allow the user to specify a file
       
  1396 	// name or a full path in the interface.
       
  1397 	// Because of this we have a mix of specifying log file details
       
  1398 	// with or without a full path.
       
  1399 	// This function will create a full path for the log file from the
       
  1400 	// name passed.  If the name passed already has a folder
       
  1401 	// specified (at least on '\' characters) then we copy
       
  1402 	// that to the out parameter.
       
  1403 	// If the name passed does not have a folder specification
       
  1404 	// within it then we prepend the log file folder.
       
  1405 
       
  1406 	static const char folder = '\\';
       
  1407 
       
  1408 	if(NULL != ::strchr(logFileName, folder))
       
  1409 	{
       
  1410 		logFilePath = logFileName;
       
  1411 	}
       
  1412 	else
       
  1413 	{
       
  1414 		GetLogFolder(logFilePath);
       
  1415 		logFilePath += "\\";
       
  1416 		logFilePath += logFileName;
       
  1417 	}
       
  1418 }
       
  1419