다음을 통해 공유


방법: 장치 플랫폼 가져오기

업데이트: 2007년 11월

.NET Compact Framework 버전 3.5 이상에서는 WinCEPlatform 열거형을 사용하여 Pocket PC와 Smartphone 중 응용 프로그램이 현재 실행되고 있는 장치 플랫폼을 확인할 수 있습니다.

.NET Compact Framework 2.0 또는 이전 버전에서는 네이티브 코드에 대한 P/Invoke 호출을 사용하여 장치 플랫폼을 반환할 수 있습니다. 다음 절차에서는 장치 플랫폼을 확인하는 데 사용할 수 있는 플랫폼의 클래스 및 열거형을 정의합니다.

.NET Compact Framework 2.0 및 이전 버전에서 장치 플랫폼을 가져오려면

  1. 프로젝트에 다음 클래스 및 열거형을 추가합니다.

    Public Class PlatformDetector
    
        Declare Function SystemParametersInfo Lib "Coredll.dll" _
            (ByVal uiAction As System.UInt32, _
            ByVal uiParam As System.UInt32, _
            ByVal pvParam As StringBuilder, _
            ByVal fWinIni As System.UInt32) As Boolean
    
    
        Private Shared SPI_GETPLATFORMTYPE As System.UInt32 = 257 
    
    
        Public Shared Function GetPlatform() As Platform 
            Dim plat As Platform = Platform.Unknown
            Select Case 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()
            End Select
    
            Return plat
    
        End Function 
    
    
        Shared Function CheckWinCEPlatform() As Platform 
            Dim plat As Platform = Platform.WindowsCE
            Dim strbuild As New StringBuilder(200)
            SystemParametersInfo(SPI_GETPLATFORMTYPE, 200, strbuild, 0)
            Dim str As String = strbuild.ToString()
            Select Case 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
            End Select
            Return plat
    
        End Function 
    End Class 
    
    
    Public Enum Platform
        PocketPC
        WindowsCE
        Smartphone
        Win32NT
        Win32S
        Win32Windows
        Unknown
    End Enum
    
    public class PlatformDetector
    {
        [DllImport("coredll.dll")]
        private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, StringBuilder pvParam, uint fWinIni);
    
        private static uint SPI_GETPLATFORMTYPE = 257;
    
        public static 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;
        }
    }
    
    public enum 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() As Byte, _
         ByVal nOutBufSize As Int32, _
         ByRef lpBytesReturned As Int32) As Boolean
    
    Private Sub DeviceType_Load(ByVal sender As Object, ByVal e As System.EventArgs)  _
        Handles MyBase.Load
    
           Try
                MessageBox.Show("Platform is " + PlatformDetector.GetPlatform().ToString())
            Catch ex As Exception
                MessageBox.Show(ex.Message.ToString())
            End Try
    
    End Sub
    
    [DllImport("coredll.dll", SetLastError = true)]
    private static extern bool KernelIoControl(Int32 dwIoControlCode,
        IntPtr lpInBuf, Int32 nInBufSize, byte[] lpOutBuf,
        Int32 nOutBufSize, ref Int32 lpBytesReturned);
    
    private void DeviceType_Load(object sender, System.EventArgs e)
    {
        try
        {
    
            MessageBox.Show("Platform is " + PlatformDetector.GetPlatform());
        }
    
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message.ToString());
        }
    }
    

코드 컴파일

이 예제에는 다음과 같은 네임스페이스에 대한 참조가 필요합니다.

참고 항목

작업

방법: 장치 ID 및 이름 가져오기

개념

.NET Compact Framework 방법 항목

기타 리소스

.NET Compact Framework의 상호 운용성