Solved

Command to reboot Windows Mobile 5 Device in .NET Compact Framework

Posted on 2007-12-04
10
3,072 Views
Last Modified: 2013-11-17
I need a command / function / whatever, so that when a user clicks a button the device does a warm boot. I played with the ExitWindowsEx function as published all over the net, but no matter how I use it, I always get an error in coredll.dll and it seems I am not alone in this.

I'm using HP Hx2400 with VB.NET CF 2.0

If you could please submit a complete working function including any constants and their required definitions in the interest of saving time. I really appreciate it.

Thanks
0
Comment
Question by:mikesims10670
  • 6
  • 4
10 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20409253
Have a look to this:
http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=2330

it has a C# and a vb.net version.
0
 
LVL 1

Author Comment

by:mikesims10670
ID: 20409381
This looks promising, but when I copy over the code in the VB example, This procedure:

    Private Sub ResetUnit()
        Dim bytesReturned As Integer = 0
        Dim IOCTL_HAL_REBOOT As Long = &H101003C
        Dim InBuf() As Integer
        Dim OutBuf() As Byte
        KernelIoControl(IOCTL_HAL_REBOOT, InBuf, 0, OutBuf, 0, bytesReturned)
    End Sub

throws an error to the IDE because InBuff and OutBuff are being used before they are assigned a value.
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 500 total points
ID: 20409410
the buffers are not necessary in this case, try with:

Private Sub ResetUnit()
        Dim bytesReturned As Integer = 0
        Dim IOCTL_HAL_REBOOT As Long = &H101003C
        KernelIoControl(IOCTL_HAL_REBOOT, Nothing, 0, Nothing, 0, bytesReturned)
End Sub

if the Nothing causes problems, use 0 instead
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Comment

by:mikesims10670
ID: 20409415
I changed

Dim InBuf() As Integer
Dim OutBuf() As Byte

to

Dim InBuf As Integer
Dim OutBuf As Byte

And I changed the Public Shared Sub KernelIoControl variables to match.

It works like a champ!

Thank you very much.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20409419
>>I changed
>>Dim InBuf() As Integer
>>Dim OutBuf() As Byte
>>to
>>Dim InBuf As Integer
>>Dim OutBuf As Byte

That's an ugly trick, try with my previous suggestion
0
 
LVL 1

Author Comment

by:mikesims10670
ID: 20409429
That works too. Thanks again!

Mike
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20409473
Are you planning to keep this question open?
0
 
LVL 1

Author Comment

by:mikesims10670
ID: 20409497
Nope!
0
 
LVL 1

Author Comment

by:mikesims10670
ID: 20409509
For anyone who is reading this as a search hot on a similar issue, the VB code that works is:

Imports System.Runtime.InteropServices

    <DllImport("coredll.dll")> _
        Public Shared Sub KernelIoControl(ByVal dwIoControlCode As Long, _
                                          ByVal lpInBuf() As Integer, _
                                          ByVal nInBufSize As Long, _
                                          ByVal lpOutBuf() As Byte, _
                                          ByVal nOutBufSize As Byte, _
                                          ByRef lpBytesReturned As Integer)
    End Sub


    Private Sub ResetUnit()
        Dim bytesReturned As Integer = 0
        Dim IOCTL_HAL_REBOOT As Long = &H101003C
        'Dim InBuf As Integer
        'Dim OutBuf As Byte
        KernelIoControl(IOCTL_HAL_REBOOT, Nothing, 0, Nothing, 0, bytesReturned)
    End Sub


    Private Sub Reboot(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            ResetUnit()
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try
    End Sub
0
 
LVL 1

Author Closing Comment

by:mikesims10670
ID: 31412778
Excellent Job! Thank you very much.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question