Export (0) Print
Expand All

How to: Reset the Device

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

Example

This code example defines the following:

  • Platform invoke declarations for the native functions in Windows 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();
    }
}


Compiling the Code

This example requires references to the following namespaces:

See Also

Community Additions

ADD
Show:
© 2014 Microsoft