Using CeSetUserNotification to start a program in .NET CF

No.of Views2096
Bookmarked2 times
Downloads 
Votes1
By  j2inet   On  17 Jul 2010 23:07:48
Tag : .NET CF , Utilities
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
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

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 CodeGain.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);
    }

 That's all.enjoy the happy coding.

 
Sign Up to vote for this article
 
About Author
 
j2inet
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Not Provided
Joined date-12 Jun 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top
</