Use C # To obtain the memory status and system status in the wince System

Source: Internet
Author: User
Tags intel pentium
I have been trying to obtain the memory and system status in wince5.0, But I have suffered from it. I used Google to search for a mess and finally found two reference articles to write the following test procedure. The implementation step is to use vs2005 to create a wince application project and add a form. Then drag two listboxes into the form and name them listbox1 and listbox2 respectively. Drag two buttons, named No btnget or btnexit, and double-click them to add events. The Code is as follows:

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. runtime. interopservices;

Namespace wincememorymanagementdemo
{
Public partial class mainform: Form
{

// Struct to retrive system info
[Structlayout (layoutkind. Sequential)]
Public struct system_info
{
Public uint dwoemid;
Public uint dwpagesize;
Public uint lpminimumapplicationaddress;
Public uint lpmaximumapplicationaddress;
Public uint dwactiveprocessormask;
Public uint dwnumberofprocessors;
Public uint dwprocessortype;
Public uint dwallocationgranularity;
Public uint dwprocessorlevel;
Public uint dwprocessorrevision;
}

// Struct to retrive memory status
[Structlayout (layoutkind. Sequential)]
Public struct memorystatus
{
Public uint dwlength;
Public uint dwmemoryload;
Public uint dwtotalphys;
Public uint dwavailphys;
Public uint dwtotalpagefile;
Public uint dwavailpagefile;
Public uint dwtotalvirtual;
Public uint dwavailvirtual;
}

// To get system information
[Dllimport ("coredll")]
Private Static extern void getsysteminfo (ref system_info psi );

// To get memory status
[Dllimport ("coredll")]
Private Static extern void globalmemorystatus (ref memorystatus BUF );

// Cnstants used for processor types
Public const int processor_intel_386 = 386;
Public const int processor_intel_timeout = 486;
Public const int processor_intel_pentium = 586;
Public const int processor_mips_r4000 = 4000;
Public const int processor_alpha_21064 = 21064;
Public const int processor_telechips_tcc79x = 2336;

Public mainform ()
{
Initializecomponent ();
}

/// <Summary>
/// Obtain information
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void btnget_click (Object sender, eventargs E)
{
Listbox1.items. Clear ();
Listbox2.items. Clear ();
Try
{
/*************************************** **************************************** ***/

Memorystatus memst = new memorystatus ();
Globalmemorystatus (ref memst );

Listbox1.items. Add ("Available page file:" + (memst. dwavailpagefile/1024). tostring () + "kb ");
Listbox1.items. Add ("application memory in use:" + (memst. dwtotalphys/1024-memst. dwavailphys/1024). tostring () + "kb ");
Listbox1.items. Add ("available physical memory:" + (memst. dwavailphys/1024). tostring () + "kb ");
Listbox1.items. Add ("available virtual memory:" + (memst. dwavailvirtual/1024). tostring () + "kb ");
Listbox1.items. Add ("size of structure:" + memst. dwlength. tostring ());
Listbox1.items. Add ("memory in use:" + memst. dwmemoryload. tostring () + "% ");
Listbox1.items. Add ("total page size:" + (memst. dwtotalpagefile/1024). tostring () + "kb ");
Listbox1.items. Add ("total physical memory:" + (memst. dwtotalphys/1024). tostring () + "kb ");
Listbox1.items. Add ("Total virtual memory:" + (memst. dwtotalvirtual/1024). tostring () + "kb ");

/*************************************** **************************************** ***/
System_info psi = new system_info ();
Getsysteminfo (ref psi );
String cputype;
Switch (PSI. dwprocessortype)
{

Case processor_intel_386:
Cputype = "Intel 386 ";
Break;
Case processor_intel_case:
Cputype = "Intel 486 ";
Break;
Case processor_intel_pentium:
Cputype = "Intel Pentium ";
Break;
Case processor_mips_r4000:
Cputype = "MIPS r4000 ";
Break;
Case processor_alpha_21064:
Cputype = "DEC Alpha 21064 ";
Break;
Case processor_telechips_tcc79x:
Cputype = "TELECHIPS-ARM926-TCC79X ";
Break;
Default:
Cputype = "(unknown )";
Break;
}

Listbox2.items. Add ("active processor mask:" + psi. dwactiveprocessormask. tostring ());
Listbox2.items. Add ("allocation granularity:" + psi. dwallocationgranularity. tostring ());
Listbox2.items. Add ("Number of processors:" + psi. dwnumberofprocessors. tostring ());
Listbox2.items. Add ("oem id:" + psi. dwoemid. tostring ());
Listbox2.items. Add ("page size:" + psi. dwpagesize. tostring ());
// Processor level (req filtering to get level)
Listbox2.items. Add ("processor level value:" + psi. dwprocessorlevel. tostring ());
Listbox2.items. Add ("processor revision:" + psi. dwprocessorrevision. tostring ());
Listbox2.items. Add ("CPU type:" + cputype );
Listbox2.items. Add ("Maximum Application address:" + psi. lpmaximumapplicationaddress. tostring ());
Listbox2.items. Add ("Minimum application address:" + psi. lpminimumapplicationaddress. tostring ());

Statusbar. Text = psi. dwprocessortype. tostring ();
}
Catch (exception ex)
{
Statusbar. Text = ex. message;
}
}

Private void btnexit_click (Object sender, eventargs E)
{
Application. Exit ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.