方法 : デバイス プラットフォームを取得します。

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

.NET Compact Framework Version 3.5 以降のバージョンで、 WinCEPlatform 列挙体を使用して、Pocket PC または Smartphone、どのデバイス プラットフォームが、アプリケーション実行されている現在確認できます。

.NET Compact Framework 2.0 または以前のバージョンでは、戻ることができますデバイス プラットフォームのプラットフォームを使用してネイティブ コードへの呼び出しを起動します。 次の手順は、クラスとデバイス プラットフォームの確認を使用しているプラットフォームの列挙体を定義します。

.NET Compact Framework 2. 0. 以前のバージョンでは、デバイス プラットフォームを取得するには

  1. プロジェクトに、次のクラスおよび列挙体を追加します。

                                Public
                                Class PlatformDetector
    
        DeclareFunction SystemParametersInfo Lib"Coredll.dll" _
            (ByVal uiAction As System.UInt32, _
            ByVal uiParam As System.UInt32, _
            ByVal pvParam As StringBuilder, _
            ByVal fWinIni As System.UInt32) AsBooleanPrivateShared SPI_GETPLATFORMTYPE As System.UInt32 = 257 
    
    
        PublicSharedFunction GetPlatform() As Platform 
            Dim plat As Platform = Platform.Unknown
            SelectCase System.Environment.OSVersion.Platform
                Case PlatformID.Win32NT
                    plat = Platform.Win32NT
                Case PlatformID.Win32S
                    plat = Platform.Win32S
                Case PlatformID.Win32Windows
                    plat = Platform.Win32Windows
                Case PlatformID.WinCE
                    plat = CheckWinCEPlatform()
            EndSelectReturn plat
    
        EndFunctionSharedFunction CheckWinCEPlatform() As Platform 
            Dim plat As Platform = Platform.WindowsCE
            Dim strbuild AsNew StringBuilder(200)
            SystemParametersInfo(SPI_GETPLATFORMTYPE, 200, strbuild, 0)
            Dim str AsString = strbuild.ToString()
            SelectCase str
                Case"PocketPC"
                    plat = Platform.PocketPC
                Case"SmartPhone"            ' Note that the strbuild parameter from the            ' PInvoke returns "SmartPhone" with an            ' upper case P. The correct casing is            ' "Smartphone" with a lower case p.
                plat = Platform.Smartphone
            EndSelectReturn plat
    
        EndFunctionEndClassPublicEnum Platform
        PocketPC
        WindowsCE
        Smartphone
        Win32NT
        Win32S
        Win32Windows
        Unknown
    EndEnum
    
                                public
                                class PlatformDetector
    {
        [DllImport("coredll.dll")]
        privatestaticexternbool SystemParametersInfo(uint uiAction, uint uiParam, StringBuilder pvParam, uint fWinIni);
    
        privatestaticuint SPI_GETPLATFORMTYPE = 257;
    
        publicstatic Platform GetPlatform()
        {
            Platform plat = Platform.Unknown;
            switch (System.Environment.OSVersion.Platform)
            {
                case PlatformID.Win32NT:
                    plat = Platform.Win32NT;
                    break;
                case PlatformID.Win32S:
                    plat = Platform.Win32S;
                    break;
                case PlatformID.Win32Windows:
                    plat = Platform.Win32Windows;
                    break;
                case PlatformID.WinCE:
                    plat = CheckWinCEPlatform();
                    break;
            }
    
            return plat;
        }
    
        static Platform CheckWinCEPlatform()
        {
            Platform plat = Platform.WindowsCE;
            StringBuilder strbuild = new StringBuilder(200);
            SystemParametersInfo(SPI_GETPLATFORMTYPE, 200, strbuild, 0);
            string str = strbuild.ToString();
            switch (str)
            {
                case"PocketPC":
                    plat = Platform.PocketPC;
                    break;
                case"SmartPhone":
                    // Note that the strbuild parameter from the// PInvoke returns "SmartPhone" with an
                    // upper case P. The correct casing is// "Smartphone" with a lower case p.
                    plat = Platform.Smartphone;
                    break;
            }
            return plat;
        }
    }
    
    publicenum Platform
    {
        PocketPC, WindowsCE, Smartphone, Win32NT, Win32S, Win32Windows, Unknown
    }
    
  2. 次の宣言と、フォームの Load イベント コードを追加します。

                                Declare
                                Function KernelIoControl Lib"CoreDll.dll" _
        (ByVal dwIoControlCode As Int32, _
         ByVal lpInBuf As IntPtr, _
         ByVal nInBufSize As Int32, _
         ByVal lpOutBuf() AsByte, _
         ByVal nOutBufSize As Int32, _
         ByRef lpBytesReturned As Int32) AsBooleanPrivateSub DeviceType_Load(ByVal sender AsObject, ByVal e As System.EventArgs)  _
        HandlesMyBase.Load
    
           Try
                MessageBox.Show("Platform is " + PlatformDetector.GetPlatform().ToString())
            Catch ex As Exception
                MessageBox.Show(ex.Message.ToString())
            EndTryEndSub
    
    [DllImport("coredll.dll", SetLastError = true)]
    privatestaticexternbool KernelIoControl(Int32 dwIoControlCode,
        IntPtr lpInBuf, Int32 nInBufSize, byte[] lpOutBuf,
        Int32 nOutBufSize, ref Int32 lpBytesReturned);
    
    privatevoid DeviceType_Load(object sender, System.EventArgs e)
    {
        try
        {
    
            MessageBox.Show("Platform is " + PlatformDetector.GetPlatform());
        }
    
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message.ToString());
        }
    }
    

コードのコンパイル方法

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

参照

処理手順

方法 : デバイス ID と名前を取得します。

概念

.NET コンパクトなフレームワーク方法を説明したトピックの検索

その他の技術情報

.NET Compact Framework の相互運用性