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.

Private Const FILE_DEVICE_HAL As Integer = &H101
Private Const METHOD_BUFFERED As Integer = 0
Private Const FILE_ANY_ACCESS As Integer = 0

Private Function CTL_CODE( _
  ByVal DeviceType As Integer, _
  ByVal Func As Integer, _
  ByVal Method As Integer, _
  ByVal Access As Integer) As Integer

    Return (DeviceType << 16) Or (Access << 14) Or (Func << 2) Or Method

End Function 

Declare Function KernelIoControl Lib "CoreDll.dll" _
    (ByVal dwIoControlCode As Integer, _
     ByVal lpInBuf As IntPtr, _
     ByVal nInBufSize As Integer, _
     ByVal lpOutBuf As IntPtr, _
     ByVal nOutBufSize As Integer, _
     ByRef lpBytesReturned As Integer _
    ) As Integer

Private Function ResetPocketPC() As Integer
    Dim bytesReturned As Integer = 0
    Return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, _
      IntPtr.Zero, 0, bytesReturned)
End Function 

Private Sub ResetDevice()
    Dim msg As String
    Dim title As String
    Dim style As MsgBoxStyle
    Dim response As MsgBoxResult
    msg = "Are you sure you want to reset the device?"
    style = MsgBoxStyle.DefaultButton2 Or _
       MsgBoxStyle.Question Or MsgBoxStyle.YesNo
    title = "Device Reset"
    response = MsgBox(msg, style, title)
    If response = MsgBoxResult.Yes Then   ' User chose Yes.
    End If

End Sub 

This example requires references to the following namespaces: