locked
Using GetNativeSystemInfo in Metro app[C#]

    Question

  • Hi

    I design a metro app, it want get the platform from CPU, I found GetNativeSystemInfo can help me solve this question

    And I use GetNativeSystemInfo in metro[C#] via DllImport

    The function is work correct. But I got fail when I run the metro in Windows App Cert Kit. 

    In my study GetNativeSystemInfo is Applies to: desktop apps | Metro style apps

    My question is, if the function support metro app, why Windows ACT return failed ?

    Thanks

    • Moved by Ronnie VernonMVP Wednesday, April 18, 2012 8:10 PM Focus (From:Windows 8 General)
    Wednesday, April 18, 2012 1:21 PM

Answers

  • GetNativeSystemInfo should be fine from a Metro style app and it passes the WACK in my tests.

    What does your pinvoke signature look like? Are you positive that this is the function that is failing? Can you reproduce this in a minimal app which you can share?

    I tested both with a native C++ app and with a blank C# app using the signature from pinvoke.net.

            public enum Platform
            {
                X86,
                X64,
                IA64,
                Unknown
            }
    
            internal const ushort PROCESSOR_ARCHITECTURE_INTEL = 0;
            internal const ushort PROCESSOR_ARCHITECTURE_IA64 = 6;
            internal const ushort PROCESSOR_ARCHITECTURE_AMD64 = 9;
            internal const ushort PROCESSOR_ARCHITECTURE_UNKNOWN = 0xFFFF;
    
            [StructLayout(LayoutKind.Sequential)]
            internal struct SYSTEM_INFO
            {
                public ushort wProcessorArchitecture;
                public ushort wReserved;
                public uint dwPageSize;
                public IntPtr lpMinimumApplicationAddress;
                public IntPtr lpMaximumApplicationAddress;
                public UIntPtr dwActiveProcessorMask;
                public uint dwNumberOfProcessors;
                public uint dwProcessorType;
                public uint dwAllocationGranularity;
                public ushort wProcessorLevel;
                public ushort wProcessorRevision;
            };
    
            [DllImport("kernel32.dll")]
            internal static extern void GetNativeSystemInfo(ref SYSTEM_INFO lpSystemInfo);
    
                SYSTEM_INFO sysInfo = new SYSTEM_INFO();
                GetNativeSystemInfo(ref sysInfo);
    

    --Rob

    • Marked as answer by Sean.Wu Friday, April 27, 2012 4:45 AM
    Thursday, April 19, 2012 12:47 AM
    Moderator

All replies

  • GetNativeSystemInfo should be fine from a Metro style app and it passes the WACK in my tests.

    What does your pinvoke signature look like? Are you positive that this is the function that is failing? Can you reproduce this in a minimal app which you can share?

    I tested both with a native C++ app and with a blank C# app using the signature from pinvoke.net.

            public enum Platform
            {
                X86,
                X64,
                IA64,
                Unknown
            }
    
            internal const ushort PROCESSOR_ARCHITECTURE_INTEL = 0;
            internal const ushort PROCESSOR_ARCHITECTURE_IA64 = 6;
            internal const ushort PROCESSOR_ARCHITECTURE_AMD64 = 9;
            internal const ushort PROCESSOR_ARCHITECTURE_UNKNOWN = 0xFFFF;
    
            [StructLayout(LayoutKind.Sequential)]
            internal struct SYSTEM_INFO
            {
                public ushort wProcessorArchitecture;
                public ushort wReserved;
                public uint dwPageSize;
                public IntPtr lpMinimumApplicationAddress;
                public IntPtr lpMaximumApplicationAddress;
                public UIntPtr dwActiveProcessorMask;
                public uint dwNumberOfProcessors;
                public uint dwProcessorType;
                public uint dwAllocationGranularity;
                public ushort wProcessorLevel;
                public ushort wProcessorRevision;
            };
    
            [DllImport("kernel32.dll")]
            internal static extern void GetNativeSystemInfo(ref SYSTEM_INFO lpSystemInfo);
    
                SYSTEM_INFO sysInfo = new SYSTEM_INFO();
                GetNativeSystemInfo(ref sysInfo);
    

    --Rob

    • Marked as answer by Sean.Wu Friday, April 27, 2012 4:45 AM
    Thursday, April 19, 2012 12:47 AM
    Moderator
  • Thanks for your response.

    My code is same as yours.

    I will test the code on Windows 8 Consumer Preview Build 8304.

    Thanks

    Monday, April 23, 2012 11:59 AM
  • Hi Sean,

    This forum is for discussion of the public Windows 8 Consumer Preview (build 8250) only. If you have access to newer builds under NDA then please address any questions through the channel from which you received the build.

    --Rob

    Monday, April 23, 2012 3:38 PM
    Moderator