There are times when it is required for an application to reset the device. Below are methods in .NET to handle each way of resetting the device.
-Common Declarations-
C#
const int POWER_STATE_RESET = 0x800000;
[System.Runtime.InteropServices.DllImport("coredll.dll")]
private Int32 SetSystemPowerState(System.Char[] psState, System.Int32 StateFlags, System.Int32 Options)
VB.NET
Const POWER_STATE_RESET As Integer = &H800000
<System.Runtime.InteropServices.DllImport("coredll.dll")> _
Private Function SetSystemPowerState(ByVal psState() As System.Char, ByVal StateFlags As System.Int32, ByVal Options As System.Int32) As Int32
End Function
-Warm Reset-
Public Sub WarmReset()
SetSystemPowerState(Nothing, POWER_STATE_RESET, 0)
End Sub
Public void WarmReset()
{
SetSystemPowerState(Nothing, POWER_STATE_RESET, 0);
}
C++
#include <windows.h>
#include <Pm.h>
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPTSTR lpCmdLine,int nCmdShow)
return (int)SetSystemPowerState(NULL, POWER_STATE_RESET, 0);
-Cold Reset-
Public Sub ColdReset()
Dim cState() As System.Char
cState = New String("ResetCold").ToCharArray
SetSystemPowerState(cState, 0, 0)
Public void ColdReset()
System.Char cState[];
cState = new string("ResetCold").ToCharArray;
SetSystemPowerState(cState, 0, 0);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
OSVERSIONINFO ovi = {0};
ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!GetVersionEx(&ovi))
return (int)GetLastError();
if ((ovi.dwMajorVersion==4 && ovi.dwMinorVersion==20) || // Windows CE .NET 4.2
(ovi.dwMajorVersion==4 && ovi.dwMinorVersion==21)) // Windows Mobile 2003 Second Edition
return (int)SetSystemPowerState(L"ResetCold", 0, 0);
else if ((ovi.dwMajorVersion==5 && ovi.dwMinorVersion==0) || // Windows CE 5.0
(ovi.dwMajorVersion==5 && ovi.dwMinorVersion==1) || // Windows Mobile 5.0
(ovi.dwMajorVersion==5 && ovi.dwMinorVersion==2)) // Windows Mobile 6.x Classic or Professional
return (int)SetSystemPowerState(L"coldreboot", 0, 0);
return ERROR_SUCCESS;
-Boot to Boost-
VB.NET *Note this only works on WinCE devices and not WM*
Public Sub BootToBoost()
cState = New String("ResetBootloader").
C# *Note this only works on WinCE devices and not WM*
Public void BootToBoost()
cState = new string("ResetBootloader").ToCharArray;
#include <winioctl.h>
#define TEK_CTL_CODE_FILE_DEVICE_POWER 0x8014
// Reset the handheld, booting to BooSt.
#define IOCTL_PMDRV_BOOT_TO_BOOTLOADER \
CTL_CODE(TEK_CTL_CODE_FILE_DEVICE_POWER, 0x816, METHOD_NEITHER, FILE_ANY_ACCESS)
(ovi.dwMajorVersion==4 && ovi.dwMinorVersion==21) || // Windows Mobile 2003 Second Edition
(ovi.dwMajorVersion==5 && ovi.dwMinorVersion==0)) // Windows CE .NET 5.0
return (int)SetSystemPowerState(L"ResetBootLoader", 0, 0);
else if ((ovi.dwMajorVersion==5 && ovi.dwMinorVersion==1) || // Windows Mobile 5.0
// Try to boot to boost using the IOCTL first (only supported on some devices).
HANDLE h = CreateFile(L"PMX1:", 0, 0, 0, 0, 0, 0);
if( h != INVALID_HANDLE_VALUE )
// If this returns, the function is not supported.
if (!DeviceIoControl(h, IOCTL_PMDRV_BOOT_TO_BOOTLOADER, 0, 0, 0, 0, 0, 0))
#if DEBUG
TCHAR szError[255];
wsprintf(szError, TEXT("DeviceIoControl() failed with %d"), GetLastError());
MessageBox(NULL, szError, NULL, MB_ICONERROR | MB_TOPMOST | MB_SETFOREGROUND);
#endif
CloseHandle(h);
else
wsprintf(szError, TEXT("CreateFile() failed with %d"), GetLastError());
Special Note: Thanks to Jacques Gourmelen for pointing out the Article on WIKI that contained the C++ examples