Solved

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

Posted on 2007-12-04
10
3,074 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

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 …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

861 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