Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

How to: Reset the Device

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

To reset the device, use platform invoke to call the native KernelIoControl function.

This code example defines the following:

  • Platform invoke declarations for the native functions in Windows Embedded CE.

  • A method named ResetDevice that displays a confirmation message box. If the user responds yes, the ResetPocktPC method resets the device.


    public const uint FILE_DEVICE_HAL = 0x00000101;
    public const uint METHOD_BUFFERED = 0;
    public const uint FILE_ANY_ACCESS = 0;

    public uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access)
    {
        return ((DeviceType << 16) | (Access << 14) | (Function << 2) | Method);
    }

    [DllImport("Coredll.dll")]
    public extern static uint KernelIoControl
    (
        uint dwIoControlCode,
        IntPtr lpInBuf,
        uint nInBufSize,
        IntPtr lpOutBuf,
        uint nOutBufSize,
        ref uint lpBytesReturned
    );

    private uint ResetPocketPC()
    {
        uint bytesReturned = 0;
        uint IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, 
          METHOD_BUFFERED, FILE_ANY_ACCESS);
        return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, 
          IntPtr.Zero, 0, ref bytesReturned);
    }

    private void ResetDevice()
    {
        DialogResult r = MessageBox.Show
        (
            "Are you sure you want to reset?",
            "Test",
            MessageBoxButtons.YesNo,
            MessageBoxIcon.Question,
            MessageBoxDefaultButton.Button2
        );

        if (r == DialogResult.Yes)
        {
            ResetPocketPC();
        }
    }



This example requires references to the following namespaces:

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.