Solved

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

Posted on 2007-12-04
10
3,060 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now