开机启动的代码

#include <apmrec.h>
#include <apmstd.h>
#include "cl_autostart.h"
#include <flogger.h>
#include <context_uids.h>

CclAutostart::CclAutostart()
:CApaDataRecognizerType(KUidcl_autostart, CApaDataRecognizerType::ENormal)
{
iCountDataTypes = 1;
}

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

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

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

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

RFileLogger iLog;
iLog.Connect();
iLog.CreateLog(_L("Autostart"),_L("Autostart"),EFileLoggingModeAppend);
iLog.Write(_L("Starting thread."));
iLog.CloseLog();
iLog.Close();

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

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

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

startAppThread->Resume();

startAppThread->Close();
}


TInt CclAutostart::StartAppThreadFunction(TAny* /*aParam*/)
{

//wait 5 seconds...
RTimer timer; // The asynchronous timer and ...
TRequestStatus timerStatus; // ... its associated request status
timer.CreateLocal(); // Always created for this thread.
// get current time (microseconds since 0AD nominal Gregorian)
TTime time;
time.HomeTime();
// add ten seconds to the time
TTimeIntervalSeconds timeIntervalSeconds(45);
time += timeIntervalSeconds;
// issue and wait
timer.At(timerStatus,time);
User::WaitForRequest(timerStatus);


// create a TRAP cleanup
CTrapCleanup * cleanup = CTrapCleanup::New();
TInt err;
if( cleanup == NULL )
{
err = KErrNoMemory;
}
else
{
TRAP( err, StartAppThreadFunctionL() );
}
delete cleanup;


if (err!=KErrNone)
User::Panic(_L("autostart"), err);
return err;
}

void CclAutostart::StartAppThreadFunctionL()
{
#ifdef __WINS__
const TUid starter_uid= KUidstarter;
RApaLsSession ls;
User::LeaveIfError(ls.Connect());
CleanupClosePushL(ls);
_LIT(filen, ""); // dummy
TThreadId dummy;
User::LeaveIfError( ls.StartDocument(filen, starter_uid, dummy) );
CleanupStack::PopAndDestroy();
#else
TFileName fnAppPath = _L("c://system//apps//starter//starter.exe");
RProcess server;

if (server.Create(fnAppPath, _L("")) != KErrNone) {
fnAppPath.Replace(0, 1, _L("e"));
User::LeaveIfError(server.Create(fnAppPath, _L("")));
}
CleanupClosePushL(server);
server.Resume();

CleanupStack::PopAndDestroy(); // server
#endif

}

EXPORT_C CApaDataRecognizerType* CreateRecognizer()
{
CApaDataRecognizerType* thing = new CclAutostart();

//start thread for our application
CclAutostart::StartThread();
return thing;
}

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

=============================

.h 文件

#if !defined(__CL_AUTOSTART_H__)
#define __CL_AUTOSTART_H__

#if !defined(__APMREC_H__)
#include <apmrec.h>
#endif

#include <apgcli.h>
#include <f32file.h>
#include <apacmdln.h>
#include <e32std.h>
#include <apmstd.h>


class CclAutostart : public CApaDataRecognizerType
{
public: // from CApaDataRecognizerType
CclAutostart();
TUint PreferredBufSize();
TDataType SupportedDataTypeL(TInt aIndex) const;
static void StartThread();
static TInt StartAppThreadFunction(TAny* aParam);
static void StartAppThreadFunctionL();

private: // from CApaDataRecognizerType
void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer);
};

#endif

=====================

转自nokia论坛

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值