Solved

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

Posted on 2007-12-04
10
3,094 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Suggested Courses
Course of the Month6 days, 13 hours left to enroll

622 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