#include "RunExeThread.h"


RunExeThread::RunExeThread( int t_id, LoggingMgr *lm )
{
	m_iThreadID = t_id;
	m_pLogger = lm;
	SetupShellExecute( );

	m_pLogger->PrintOut( QString("Thread ")+QString::number(t_id)+QString(" invoked"));
}



RunExeThread::SetupShellExecute( void )
{
	char *buf = (char *)malloc( sizeof( char ) * 3 );

	m_hwnd = NULL;
	m_lpOperation = "open";
	m_lpFile = "realsync.exe";
	m_lpParameters = itoa( m_iThreadID,buf,10);
	m_lpDirectory = "c:\\home\\dev\\rssauto\\rssclient\\release\\thred";
	m_nShowCmd = SW_SHOWNORMAL;

}	

/*         ShellExecute ERRORS::
0  The operating system is out of memory or resources. 
ERROR_FILE_NOT_FOUND  The specified file was not found. 
ERROR_PATH_NOT_FOUND  The specified path was not found. 
ERROR_BAD_FORMAT  The .exe file is invalid (non-Win32® .exe or error in .exe image). 
SE_ERR_ACCESSDENIED  The operating system denied access to the specified file.  
SE_ERR_ASSOCINCOMPLETE  The file name association is incomplete or invalid. 
SE_ERR_DDEBUSY  The DDE transaction could not be completed because other DDE transactions were being processed. 
SE_ERR_DDEFAIL  The DDE transaction failed. 
SE_ERR_DDETIMEOUT  The DDE transaction could not be completed because the request timed out. 
SE_ERR_DLLNOTFOUND  The specified dynamic-link library was not found.  
SE_ERR_FNF  The specified file was not found.  
SE_ERR_NOASSOC  There is no application associated with the given file name extension. 
SE_ERR_OOM  There was not enough memory to complete the operation. 
SE_ERR_PNF  The specified path was not found. 
SE_ERR_SHARE  A sharing violation occurred. 
*/








void RunExeThread::run( void )
{
	int result;
	result = (int)ShellExecute( m_hwnd, m_lpOperation,m_lpFile,m_lpParameters,m_lpDirectory,m_nShowCmd );
	
	if ( result < 32 )
	{
		m_pLogger->PrintOut( "ERROR: ShellExecute returned an error" );
	}

}
