Vibration on Windows Mobile



I remember a while ago that I needed to enable the vibration for a client's application. So I googled a bit and found the similar codes like below... And today, I found some people are looking for this solution on MSDN... So I decided to post it in C# and hope it will give some people a heads up...



       /// <summary>
        /// This function plays the specified vibration.
        /// </summary>
        /// <param name="cvn" />Must be 0
        /// <param name="rgvn" />Must be NULL
        /// <param name="fRepeat" />A Boolean value that indicates whether the song 
        /// should be repeated. If this parameter is equal to TRUE, it will refer to dwTimeout 
        /// to determine how long the vibration song should play.
        /// <param name="dwTimeout" />Must be INFINITE
        /// <returns></returns>
        /// <remarks>This API is not supported by Windows Mobile 6 Professional.</remarks>
        [DllImport("aygshell.dll", EntryPoint = "Vibrate")]
        private static extern int VibrateStart(int cvn, IntPtr rgvn, bool fRepeat, uint dwTimeout);

        /// <summary>
        /// Stops all current vibration songs.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// This API not supported by Windows Mobile 6 Professional.
        /// </remarks>
        [DllImport("aygshell.dll")]
        private static extern int VibrateStop();

        private const uint INFINITE = 0xffffffff;

        /// <summary>
        /// Start the mobile vibration.
        /// <para>This is not supported by Windows Mobile 6 Professional.</para>
        /// </summary>
        /// <returns></returns>
        public static int StartVibrate()
        {
            return VibrateStart(0, IntPtr.Zero, true, INFINITE);
        }

        /// <summary>
        /// Stops all current vibration.
        /// <para>This is not supported by Windows Mobile 6 Professional.</para>
        /// </summary>
        public static void StopVibrate()
        {
            VibrateStop();
        }


Related Posts

In case you missed it

A short update from me
A short update from me
It has been a while since I post a blog page on Blogger which was created back in 2013. So I took an opportunity to...
Showcase the blog site elements
Showcase the blog site elements
The standard paragraphs Welcome to this demo page! Here, you’ll get an exclusive preview of our cutting-edge platform designed to revolutionise your digital experience. Our...
Issue with
Issue with "Don't track your own pageviews"
Do you use your own domain name with Blogger? Do you place “Blogger’s Stats Widget” on your page? Or do you regularly check up the...