方法 : デバイスをリセットします。

[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 空白のトピックは、プレースホルダーとして挿入されています。]

デバイスをリセットするには、使用プラットフォームはネイティブ KernelIoControl 関数を呼び出す呼び出し。

使用例

コード例を次を定義します。

  • プラットフォーム呼び出し Windows Embedded CE でネイティブ関数の宣言。

  • ResetDevice 確認のメッセージ ボックスを表示する名前付きメソッド。 ユーザーが"はい"を応答、ResetPocktPC メソッド デバイス リセットされます。

                        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();
        }
    }

コードのコンパイル方法

この例では、次の名前空間への参照が必要です。

参照

その他の技術情報

.NET Compact Framework の相互運用性