Solved

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

Posted on 2007-12-04
10
3,056 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:mikesims10670
Comment Utility
That works too. Thanks again!

Mike
0
 
LVL 55

Expert Comment

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

Author Comment

by:mikesims10670
Comment Utility
Nope!
0
 
LVL 1

Author Comment

by:mikesims10670
Comment Utility
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
Comment Utility
Excellent Job! Thank you very much.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

17 Experts available now in Live!

Get 1:1 Help Now