Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Using CeSetUserNotification to start a program

, 30 Jan 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
A few days ago I got a message from a developer that was trying to use CeRunAppAtTime to schedule an application to start up. As I had mentioned in a previous post instead of using this function one should use CeSetUserNotification since on more recent devices CeRunAppAtTime is not as reliable (not

A few days ago I got a message from a developer that was trying to use CeRunAppAtTime to schedule an application to start up. As I had mentioned in a previous post instead of using this function one should use CeSetUserNotification since on more recent devices CeRunAppAtTime is not as reliable (not to mention it is marked as deprecated in the MSDN documentation).

The developer asked me for an example of how to call the method from .Net so I put together an example for him. I am sharing the example below and plan to later update my article at CodeProject.com on Automatically Starting a Windows Mobile Program with this same code.

public static extern IntPtr CeSetUserNotification(IntPtr hNotification, string application, 
                                                   SystemTime startTime,
                                                   UserNotification notification);

[DllImport("CoreDLL.dll")]
public static extern int FileTimeToSystemTime(ref long lpFileTime, SystemTime lpSystemTime);
[DllImport("CoreDLL.dll")]
public static extern int FileTimeToLocalFileTime(ref long lpFileTime, ref long lpLocalFileTime);

    [StructLayout(LayoutKind.Sequential)]
    public class UserNotification
    {
        public int ActionFlags;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string DialogTitle;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string DialogText;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string SoundPath;
        public int MaxSoundPath;
        public IntPtr Reserved;

        public UserNotification()
        {
            DialogTitle = String.Empty;
            DialogText = String.Empty;
            SoundPath = String.Empty;
            MaxSoundPath = 0;
            Reserved = IntPtr.Zero;
            ActionFlags = 0;
        }
    }

    public static void RunAppAtTime(string applicationEvent, DateTime startTime)
    {
        long fileTimeUTC = startTime.ToFileTime();
        long fileTimeLocal = 0;
        UserNotification notification;
        notification = new UserNotification();
        notification.ActionFlags = 0;
        notification.Reserved = IntPtr.Zero;

        SystemTime systemStartTime = new SystemTime();
        FileTimeToLocalFileTime(ref fileTimeUTC, ref fileTimeLocal);
        FileTimeToSystemTime(ref fileTimeLocal, systemStartTime);
        CeSetUserNotification(IntPtr.Zero ,applicationEvent, systemStartTime, 
                              notification);
    }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Joel Ivory Johnson
Software Developer Razorfish
United States United States
I attended Southern Polytechnic State University and earned a Bachelors of Science in Computer Science and later returned to earn a Masters of Science in Software Engineering.
 
For the past few years I've been providing solutions to clients using Microsoft technologies for web and Windows applications.
 
While most of my CodeProject.com articles are centered around Windows Phone it is only one of the areas in which I work and one of my interests. I also have interest in mobile development on Android and iPhone. Professionally I work with several Microsoft technologies including SQL Server technologies, Silverlight/WPF, ASP.Net and others. My recreational development interest are centered around Artificial Inteligence especially in the area of machine vision.
 
Twitter:@J2iNet
Follow on   Twitter   LinkedIn

Comments and Discussions

 
QuestionKill the notification been set? PinmemberHGolfer5-Feb-14 8:56 
GeneralWake PinmemberKentCampbell28-Apr-10 11:15 
AnswerRe: Wake PinmemberPaul Heil22-Jun-11 4:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 30 Jan 2010
Article Copyright 2010 by Joel Ivory Johnson
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid