6.17. How do I programmatically soft reset the device?
The device can be soft reset through P/Invoking of the KernelIoControl function, as demonstrated in the code below. For more information on how to use the function and extend the functionality of this sample, refer to Visual Studio .NET Help.
Note: On Smartphone devices, this will only work if you are signed with a privileged certificate. //C#
using System.Runtime.InteropServices;
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
);
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 Form1_Load(object sender, System.EventArgs e)
{
DialogResult r = MessageBox.Show
(
"Are you sure you want to reset?",
"Test",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2
);
if (r == DialogResult.Yes)
{
ResetPocketPC();
}
}
'VB
Public Const FILE_DEVICE_HAL As Integer = &H101
Public Const METHOD_BUFFERED As Integer = 0
Public Const FILE_ANY_ACCESS As Integer = 0
Public 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 'CTL_CODE
<DllImport("Coredll.dll")> _
Public Shared Function KernelIoControl _
( _
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
End Function
Function ResetPocketPC() As Integer
Dim bytesReturned As Integer = 0
Dim IOCTL_HAL_REBOOT As Integer = CTL_CODE(FILE_DEVICE_HAL, _
15, METHOD_BUFFERED, FILE_ANY_ACCESS)
Return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, _
IntPtr.Zero, 0, bytesReturned)
End Function 'ResetPocketPC