Hi all,
Here is what I succeeded in making with the whole information collected in the forum. 😃
autostart.mmp
=========
TARGET autostart.mdl
TARGETTYPE MDL
UID 0x10003A19 0x10008A2F
TARGETPATH \system\recogs
SOURCEPATH ..\src
SOURCE autostart.cpp
USERINCLUDE . ..\inc
SYSTEMINCLUDE . \epoc32\include
LIBRARY euser.lib apparc.lib
LIBRARY apmime.lib efsrv.lib apgrfx.lib
autostart.cpp
========
// INCLUDE FILES
#include "autostart.h"
// ================= MEMBER FUNCTIONS =======================
CMyRecognizer::CMyRecognizer()
:CApaDataRecognizerType(KUidemAMRec, CApaDataRecognizerType::ENormal)
{
iCountDataTypes = 1;
}
TUint CMyRecognizer::PreferredBufSize()
{ // no buffer recognition yet
return 0;
}
TDataType CMyRecognizer::SupportedDataTypeL(TInt /*aIndex*/) const
{
return TDataType();
}
void CMyRecognizer:😃oRecognizeL(const TDesC& /*aName*/, const TDesC8& /*aBuffer*/)
{ // this function is never called
}
void CMyRecognizer::StartThread()
{
TInt res = KErrNone;
//create a new thread for starting our application
RThread * startAppThread;
startAppThread = new RThread();
User::LeaveIfError( res = startAppThread->Create(
_L("MyThreadName"😉,
CMyRecognizer::StartAppThreadFunction,
KDefaultStackSize,
KMinHeapSize,
KMinHeapSize,
NULL,
EOwnerThread) );
startAppThread->SetPriority(EPriorityNormal/*EPriorityLess*/);
startAppThread->Resume();
startAppThread->Close();
}
TInt CMyRecognizer::StartAppThreadFunction(TAny* /*aParam*/)
{
User::After(2000000);
// create an active scheduler
CActiveScheduler * scheduler = new CActiveScheduler();
if( scheduler == NULL )
return KErrNoMemory;
CActiveScheduler::Install(scheduler);
// create a TRAP cleanup
CTrapCleanup * cleanup = CTrapCleanup::New();
TInt err;
if( cleanup == NULL )
{
err = KErrNoMemory;
}
else
{
TRAP( err, StartAppThreadFunctionL() );
}
delete cleanup;
delete CActiveScheduler::Current();
return err;
}
// thread function to start our application
void CMyRecognizer::StartAppThreadFunctionL()
{
// absolute file path to our application to be launched automatically
TFileName fnAppPath = _L("\\system\\apps\\someapp\\somefile.app"😉;
RFs fsSession; //file server session
User::LeaveIfError(fsSession.Connect());
CleanupClosePushL(fsSession);
TFindFile findFile( fsSession );
User::LeaveIfError( findFile.FindByDir(fnAppPath, KNullDesC) );
CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
cmdLine->SetLibraryNameL( findFile.File() );
cmdLine->SetCommandL( EApaCommandOpen );
RApaLsSession ls;
User::LeaveIfError(ls.Connect());
CleanupClosePushL(ls);
User::LeaveIfError( ls.StartApp(*cmdLine) );
CleanupStack::PopAndDestroy(3); // Destroy fsSession, ls and cmdLine
}
// The gate function - ordinal 1
EXPORT_C CApaDataRecognizerType* CreateRecognizer()
{
CApaDataRecognizerType* thing = new CMyRecognizer();
//start thread for our application
CMyRecognizer::StartThread();
return thing;
}
// DLL entry point
GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
{
return KErrNone;
}
Then :
launch autostart.dsw (environment)
insert somefile.dsp (project)
define dependencies on autostart
select autostart as active project, build and launch :P
This runs on emulator but I don't know wether it works on real hardware.
I'm not sure on Uid3 value 0x10008A2F. I took it from cmatthee. 😮ops:
I'm not sure if that you were looking for.
In return could you indicate to me how to rock an application in background task (i.e for waiting some event) ? I will really appreciate. :P
barmal