Geeks With Blogs
Prabhu Kumar a tech twaddler..
Recently, I saw a video by Jim Wilson on running applications at specific events. He used CeRunAppAtEvent() native api, from managed code, to register an application to run when the device wakes up. Lets look at the API,

BOOL CeRunAppAtEvent(TCHAR *pwszAppName, LONG lWhichEvent);

pwszAppName: string which specifies the name of the application to be started. This string can also specify a named event. In case of a named event, the event will be opened and signaled. The named event should be of the format:

"\\\\.\\Notofications\\NamedEvents\\Event Name"

"Event Name" is the application defined event name

lWhichEvent: Specifies the event at which the application has to be started, it can take the following values,

NOTIFICATION_EVENT_DEVICE_CHANGE

 A PC Card device changed.

NOTIFICATION_EVENT_INTERNET_PROXY_CHANGE

 The Internet Proxy used by the device has changed.

NOTIFICATION_EVENT_IR_DISCOVERED

 The device discovered a server by using infrared communications.

NOTIFICATION_EVENT_NET_CONNECT

 The device connected to a network.

NOTIFICATION_EVENT_NET_DISCONNECT

 The device disconnected from a network.

NOTIFICATION_EVENT_NONE

 No events occurred. Remove all event registrations for this application.

NOTIFICATION_EVENT_OFF_AC_POWER

 The user turned the alternating current (AC) power off.

NOTIFICATION_EVENT_ON_AC_POWER

 The user turned the AC power on.

NOTIFICATION_EVENT_RESTORE_END

 A full device data restore completed.

NOTIFICATION_EVENT_RNDIS_FN_DETECTED

 RNDISFN interface is instantiated.

NOTIFICATION_EVENT_RS232_DETECTED

 An RS232 connection was made.

NOTIFICATION_EVENT_SYNC_END

 Data synchronization finished.

NOTIFICATION_EVENT_TIME_CHANGE

 The system time changed.

NOTIFICATION_EVENT_TZ_CHANGE

 The time zone changed.

NOTIFICATION_EVENT_WAKEUP

 The device woke up.



NOTIFICATION_EVENT_NONE unregisters all the events associated with that application.

I have the following two functions,

void RegisterApp()
{
    BOOL ret;
    ret = CeRunAppAtEvent(TEXT("\\Windows\\BubbleBreaker.exe"), NOTIFICATION_EVENT_WAKEUP);
    if(!ret)
    {
        printf("RegisterApp:CeRunAppAtEvent failed, err:0x%x\r\n", GetLastError());
    }
}


void UnRegisterApp()
{
    BOOL ret;
    ret = CeRunAppAtEvent(TEXT("\\Windows\\BubbleBreaker.exe"), NOTIFICATION_EVENT_NONE);
    if(!ret)
    {
        printf("UnRegisterApp:CeRunAppAtEvent failed, err:0x%x\r\n", GetLastError());
    }
}


So, whenever the device wakes up from sleep, the BubbleBreaker game will start. To simulate a device sleep and wake up on the emulator, select File -> Save State and Exit from the Emulator menu. To wake the device up, select Tools -> Connect to Device... from Visual Studio (2005).

Here's a video for you folks,



Posted on Monday, September 28, 2009 11:30 AM Applications | Back to top


Comments on this post: Applications: Running an application when a specified event occurs

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © TechTwaddle | Powered by: GeeksWithBlogs.net