SO WIRD'S GEMACHT: Das Gerät zurücksetzen

Dieser Dokumentation für die Vorschau nur ist und in späteren Versionen geändert. Leere Themen wurden als Platzhalter eingefügt.]

Um das Gerät zurückzusetzen, rufen Sie verwenden Plattformaufrufs die systemeigenen KernelIoControl-Funktion auf.

Beispiel

In diesem Codebeispiel definiert Folgendes:

  • Plattformaufrufdeklarationen für die systemeigenen Funktionen in Windows Embedded CE.

  • Eine Methode mit dem Namen ResetDevice, die ein Bestätigungsmeldungsfeld anzeigt. Wenn der Benutzer mit Ja antwortet, setzt die ResetPocktPC-Methode das Gerät zurück.

                        Private
                        Const FILE_DEVICE_HAL AsInteger = &H101
PrivateConst METHOD_BUFFERED AsInteger = 0
PrivateConst FILE_ANY_ACCESS AsInteger = 0

PrivateFunction CTL_CODE( _
  ByVal DeviceType AsInteger, _
  ByVal Func AsInteger, _
  ByVal Method AsInteger, _
  ByVal Access AsInteger) AsIntegerReturn (DeviceType << 16) Or (Access << 14) Or (Func << 2) Or Method

EndFunctionDeclareFunction KernelIoControl Lib"CoreDll.dll" _
    (ByVal dwIoControlCode AsInteger, _
     ByVal lpInBuf As IntPtr, _
     ByVal nInBufSize AsInteger, _
     ByVal lpOutBuf As IntPtr, _
     ByVal nOutBufSize AsInteger, _
     ByRef lpBytesReturned AsInteger _
    ) AsIntegerPrivateFunction ResetPocketPC() AsIntegerDim bytesReturned AsInteger = 0
    Dim IOCTL_HAL_REBOOT AsInteger = CTL_CODE(FILE_DEVICE_HAL, _
      15, METHOD_BUFFERED, FILE_ANY_ACCESS)
    Return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, _
      IntPtr.Zero, 0, bytesReturned)
EndFunctionPrivateSub ResetDevice()
    Dim msg AsStringDim title AsStringDim style As MsgBoxStyle
    Dim response As MsgBoxResult
    msg = "Are you sure you want to reset the device?"
    style = MsgBoxStyle.DefaultButton2 Or _
       MsgBoxStyle.Question Or MsgBoxStyle.YesNo
    title = "Device Reset"
    response = MsgBox(msg, style, title)
    If response = MsgBoxResult.Yes Then   ' User chose Yes.
       ResetPocketPC()
    EndIfEndSub
                        public
                        const
                        uint FILE_DEVICE_HAL = 0x00000101;
    publicconstuint METHOD_BUFFERED = 0;
    publicconstuint FILE_ANY_ACCESS = 0;

    publicuint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access)
    {
        return ((DeviceType << 16) | (Access << 14) | (Function << 2) | Method);
    }

    [DllImport("Coredll.dll")]
    publicexternstaticuint KernelIoControl
    (
        uint dwIoControlCode,
        IntPtr lpInBuf,
        uint nInBufSize,
        IntPtr lpOutBuf,
        uint nOutBufSize,
        refuint lpBytesReturned
    );

    privateuint ResetPocketPC()
    {
        uint bytesReturned = 0;
        uint IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, 
          METHOD_BUFFERED, FILE_ANY_ACCESS);
        return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, 
          IntPtr.Zero, 0, ref bytesReturned);
    }

    privatevoid ResetDevice()
    {
        DialogResult r = MessageBox.Show
        (
            "Are you sure you want to reset?",
            "Test",
            MessageBoxButtons.YesNo,
            MessageBoxIcon.Question,
            MessageBoxDefaultButton.Button2
        );

        if (r == DialogResult.Yes)
        {
            ResetPocketPC();
        }
    }

Kompilieren des Codes

In diesem Beispiel sind Verweise auf die folgenden Namespaces erforderlich:

Siehe auch

Weitere Ressourcen

Interoperabilität in .NET Compact Framework