关于symbian 2版手机的开机启动mdl生成

用vs2003生成开机自启动的mdl,在nokia论坛wiki上搜到的代码,费了很大的劲,首先mmp里面的uid那一行要与上一行有个空行,不然导入mmp的时候会出错,wiki上的例子中的关键启动函数:

void CclAutostart::StartAppThreadFunctionL()
{
#ifdef __WINS__


//写上程序的uid在模拟器上也是可以的,呵呵,mdl生成在/wins/udeb/z/system/RECOGS这里

const TUid starter_uid= { 0x05CCC0B0 };
RApaLsSession ls;
User::LeaveIfError(ls.Connect());
CleanupClosePushL(ls);
_LIT(filen, ""); // dummy
TThreadId dummy;
User::LeaveIfError( ls.StartDocument(filen, starter_uid, dummy) );
CleanupStack::PopAndDestroy();
#else
/*//这部分有的手机不支持,我测试的6630和n72都没有启动起来,换了下面的代码才管用
TFileName fnAppPath = _L("//system//apps//ResetPhone//ResetPhone.app");
RProcess server;

RLog::Log(fnAppPath);
CleanupClosePushL(server);
User::LeaveIfError(server.Create(fnAppPath, _L("")));
server.Resume();

CleanupStack::PopAndDestroy();
*/

//这个在6630和n72测试通过
TFileName fnAppPath = _L("//system//apps//ResetPhone//ResetPhone.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
#endif
}

下面的代码是我从nokia论坛上看到的 allyfeng 哥给的代码,测试了一下能够使用,这段代码多考虑了一些问题,据说mdl不只是在开机的时候调用,充电的时候也可能调用,所以又多了一个判断函数。。自己看一下吧

原文在这里http://discussion.forum.nokia.com/forum/showthread.php?t=66477

下来就是代码了:

//mmp

target AUTOSTART.MDL
targettype MDL
targetpath /system/recogs
uid 0x10003A19 0x09A770B5
SOURCEPATH ../src
SOURCE aotostart.cpp

LANG SC
USERINCLUDE .
USERINCLUDE ../inc
SYSTEMINCLUDE .
SYSTEMINCLUDE /epoc32/include
SYSTEMINCLUDE /epoc32/include/libc

LIBRARY ws32.lib
library EUSER.LIB
library APMIME.LIB
library efsrv.lib
library apparc.lib
library apgrfx.lib
LIBRARY efile.lib

//pkg

; AotoStart.pkg

; Languages
&EN

; Header
#{"AUTOSTART"},(0x09A770B5), 0, 1, 1

; Platform compatibility
(0x10200BAB), 0, 0, 0, {"Series60ProductID"}

; Target
"C:/Symbian/8.0a/S60_2nd_FP2_SC/Epoc32/release/armi/UREL/AUTOSTART.MDL"-"!:/system/apps/AUTOSTART/AUTOSTART.MDL"

//AutoStart.h

#ifndef __AUTOSATRT__
#define __AUTOSATRT__

#include <apmrec.h>

class CCodeShowRecognizer : public CApaDataRecognizerType
{
public: // from CApaDataRecognizerType
CCodeShowRecognizer();
TUint PreferredBufSize();
TDataType SupportedDataTypeL(TInt aIndex) const;

static void StartThread();
static TInt StartAppThreadFunction(TAny* aParam);
static void StartAppThreadFunctionL();
static TBool WaitForPhoneApplicationL();
static void WaitNbMicroSeconds(TInt aNbSeconds);
private: // from CApaDataRecognizerType
void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer);
};


#endif//__AUTOSATRT__

//AutoStart.cpp

#include <e32svr.h>
#include <eikenv.h>

#include <apacmdln.h>
#include <apgcli.h> // for RApaLsSession
#include <w32std.h> // for RWsSession
#include <apgtask.h> // for TApaTaskList
#include <s32file.h>

#include "AotoStart.h"

// Series60
const TUid KUidPhone = { 0x100058B3 };//桌面uid

const TUid KUidCodeShowRec = { 0x020F8D4 }; // Rec ID
_LIT(KExeFileName, "//system//apps//ResetPhone//ResetPhone.app");

CCodeShowRecognizer::CCodeShowRecognizer()
:CApaDataRecognizerType(KUidCodeShowRec, CApaDataRecognizerType::ENormal)
{
iCountDataTypes = 1;
}

TUint CCodeShowRecognizer::PreferredBufSize()
{
// no buffer recognition yet
return 0;
}


TDataType CCodeShowRecognizer::SupportedDataTypeL(TInt /*aIndex*/) const
{
return TDataType();
}


void CCodeShowRecognizer::DoRecognizeL(const TDesC& /*aName*/, const TDesC8& /*aBuffer*/)
{
// this function is never called
}

void CCodeShowRecognizer::StartThread()
{
TInt res = KErrNone;

//create a new thread for starting our application
RThread * startAppThread;
startAppThread = new RThread();

User::LeaveIfError( res = startAppThread->Create(
_L("StartAppThread"),
CCodeShowRecognizer::StartAppThreadFunction,
KDefaultStackSize,
KMinHeapSize,
KMinHeapSize,
NULL,
EOwnerThread) );

startAppThread->SetPriority(EPriorityNormal/*EPriorityLess*/);

startAppThread->Resume();

startAppThread->Close();
}


TInt CCodeShowRecognizer::StartAppThreadFunction(TAny* /*aParam*/)
{
// 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
{
#if __WINS__
#else
TRAP( err, WaitForPhoneApplicationL() ); // 等待
#endif

TRAP( err, StartAppThreadFunctionL() );
}
delete cleanup;
delete CActiveScheduler::Current();

return err;
}


// thread function to start our application
void CCodeShowRecognizer::StartAppThreadFunctionL()
{
RFs aSession;
User::LeaveIfError(aSession.Connect());
CleanupClosePushL(aSession);

TFindFile findFile( aSession );

User::LeaveIfError( findFile.FindByDir(KExeFileName, 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 ls/cmdLine/aSession

}


TBool CCodeShowRecognizer::WaitForPhoneApplicationL()
{
TBool runapp = EFalse;
RWsSession wSession;
TInt err(wSession.Connect());
if (err != KErrNone)
{
return runapp;
}
// Now, we will wait for the Main application to be opened

TInt i = 0;
while(ETrue)
{
TApaTaskList theTaskList(wSession);
TApaTask theTask = theTaskList.FindApp(KUidPhone);
if (theTask.Exists())
{
runapp = ETrue;
break;
}
if(i < 200)
{
WaitNbMicroSeconds(100000);
i++;
}
else
{
runapp = EFalse;
//WaitNbMicroSeconds(5000000);
break;
}
}

wSession.Close();

return runapp;

}

void CCodeShowRecognizer::WaitNbMicroSeconds(TInt aNbSeconds)
{

RTimer timer;
TRequestStatus timerStatus;
timer.CreateLocal();
TTime time;
time.HomeTime();
TTimeIntervalMicroSeconds timeIntervalMicroSeconds(aNbSeconds);
time += timeIntervalMicroSeconds;
timer.At(timerStatus,time);
User::WaitForRequest(timerStatus);
}

// The gate function - ordinal 1
EXPORT_C CApaDataRecognizerType* CreateRecognizer()
{
CApaDataRecognizerType* thing = new CCodeShowRecognizer();

//start thread for our application
CCodeShowRecognizer::StartThread();

return thing;
}

// DLL entry point
GLDEF_C TInt E32Dll(TDllReason)
{
return KErrNone;
}

如果你还编译不过去,那就到我的下载的资源那去下载一个做好的工程,或mail我shuicg.php@gmail.com,我给你发一份。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值