How to write an application to detect the platform type of Windows CE

Source: Internet
Author: User
Keywords We run application platform class operating system

When developing a Windows CE application, it is often necessary to detect the platform type to see if our application runs on the pocket PC, smartphone, or Windows CE. In this article, we describe how to write an application that detects the currently running platform type.

When developing a Windows CE operating system, we encounter another situation where some applications limit the operating system platform that is running, such as allowing only the Pocket PC to run. And if we want to run on Windows CE, we need to modify the operating system platform type. Note: This situation can only occur when testing, should not modify the actual product platform type, otherwise it will cause a lot of security problems.

To create a platform detection program
First, we need to create an application to detect the current platform type, we use C + + and platform. Builder to create this program.

The process of creating OS design and compilation is skipped here, referring to the "Windows CE 6.0 R2 development experience." We first platform. Builder creates a subproject (Subporject), finds the Subporject node in Solution Explorer, and right-clicks the add New porject to start the wizard.

In the wizard, select WCE Creator to change the project name to "Checkplatform".

In order to write less code, we choose "Hello World" creator, in general, we should choose simple Windows Embedded CE creator.

We found the CheckPlatform.cpp file in the source files node in the Checkplatform (project name) in the subprojects node. Locate the WndProc function in the file and modify the code to:

TCHAR szplatform[1024];

Switch (message)

{

Case WM_PAINT:

HDC = BeginPaint (hWnd, &ps);

Todo:add any drawing the code here ...

RECT RT;

GetClientRect (HWnd, &RT);

if (SystemParametersInfo spi_getplatformtype,sizeof (szplatform), szplatform,0)!=0)

{

DrawText (hdc, Szplatform, _tcslen (szplatform), &rt, Dt_center);

}

EndPaint (HWnd, &ps);

Break;

Default:

Return DefWindowProc (hWnd, message, WParam, LParam);

}

The code does not write well, mainly to verify the SystemParametersInfo function, we will platform. Type is displayed on the form. Normally, we should use the following code to determine the operating platform:

if (SystemParametersInfo spi_getplatformtype,sizeof (szplatform), szplatform,0)!=0)

{

if (lstrcmp (Szplatform,text ("pocket")) ==0)

; Pocket PC

else if (lstrcmp (Szplatform,text ("Smartphone")) ==0)

; Smartphone

}

If you use the Spi_getoeminfo parameter, we can obtain OEM information and if the return string includes "Microsoft DeviceEmulator", the current application is running in the emulator.

When the Checkplatform program is compiled, it is automatically added to the Nk.bin. We can run the application through command Shell. After calling attach device to start the Windows CE operating system, select Target Control (Accelerator Press) in the target menu and enter "s Chekplatform" to run the Checkplatform program.

Well, finally, look at the results of the operation:

Modifying the type of operating system
The above topic is actually a lot of articles have been discussed. But in the actual work, we will encounter some platform migration work. We will first run Windows Mobile software on Windows CE to verify functionality. But some software detects the operating system type, can we run the test platform type application on Windows CE without modifying the software code?

Platform of Windows CE operating system. The type value is specified in the BSP and can be modified by modifying the platform in the BSP. Type to change the platform of the system. Type. Note: This situation can only occur when testing, should not modify the actual product platform type, otherwise it will cause a lot of security problems.

We open the source code for Windows CE 6.0 R2, located in:

X:wince600platformdeviceemulatorsrcinc

We modify the DeviceEmulator code, and if it is the code for the other platform, go to the specified location in the corresponding BSP folder. In the BSP Inc folder, we'll find a ioctl_cfg.h file.

In the Ioctl_cfg.h file, we'll find the following code:

#if tabbed (Project_smartfon)

#define IOCTL_PLATFORM_TYPE (L "SmartPhone")

#elif Tabbed (PROJECT_WPC)

#define IOCTL_PLATFORM_TYPE (L "POCKETPCSSDK")

#else

#define IOCTL_PLATFORM_TYPE (L "DeviceEmulator")

#endif

#define IOCTL_PLATFORM_OEM (L "Microsoft deviceemulator")

The BSP of Device emulator distinguishes between different platform types by compiling options, and platform if it is a Windows CE system. Type is deviceemulator. OK, we can "trick" the operating system by modifying the value of Ioctl_platform_type to let the application think that it is running on the Pocket PC or Smartphone. Note: Windows Mobile applications may not be able to run directly on Windows CE because of the huge differences between Windows Mobile and the Windows CE function library.

After modifying the ioctl_platform_type, we need to recompile the BSP to complete the PLATFORM. The modification of type. In the Build menu, select Rebuild Current BSP and subprojects in advanced build commands.

We can compile BSP and Subporject, invoke Buildrel and makeimg to generate new Nk.bin. In this way, we can save a lot of time to recompile. The BSP is compiled in about a few minutes on my machine, and it takes about 20 minutes to rebuild the operating system.

After the success of the NK compilation, choose Attach Device, rerun system and Checkplatform program, will get the following running result:

Finally, you need to be prompted that this method only detects platform through the SystemParametersInfo API. The application for type is valid. If the software uses other methods to detect platform. Type, that requires specific analysis of the specific problem.

Related Article

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.