Storage devices extend the amount of data stored in a Windows CE device from the maximum allowed in the Object Store. The most common type of storage device is Compact Flash (CF) and ATA cards, although CDROM, DVD, FAT, and other storage devices are becoming more widespread.
Most storage devices are removable, so knowing when the user puts in or takes out a device can be important. In Windows CE a WM_DEVICECHANGE message is sent to the main application window when a removable storage device is added or removed. You need to include the file dbt.h when using this message. You can respond to this message using the following code in the window's message-processing function.
case WM_DEVICECHANGE: switch (wParam) { case DBT_DEVICEARRIVAL: case DBT_DEVICEREMOVECOMPLETE: Listing3_5(wParam, (DEV_BROADCAST_HDR*)lParam); break;
The wParam parameter has the value DBT_DEVICEARRIVAL when a device is inserted, and DBT_DEVICEREMOVECOMPLETE when the device is removed (Listing 3.5). You should note that the WM_DEVICECHANGE message is also sent when any PCMCIA (such as modem or network card) or other removable device is inserted or removed. Your application will determine whether a storage device caused the message to be sent using the techniques shown in Listing 3.6.
void Listing3_5(WORD wParam, DEV_BROADCAST_HDR* dbt) { // Must include dbt.h if(wParam == DBT_DEVICEARRIVAL) cout ≪ _T("Device inserted") ≪ endl; else if(wParam == DBT_DEVICEREMOVECOMPLETE) cout ≪ _T("Device removed") ≪ endl; } |
A special situation occurs when the Windows CE device is turned on. Windows CE simulates a removal and insertion of the device before applications are allowed to access the device. This means your application will receive two WM_DEVICECHANGE messages (a DBT_DEVICEREMOVECOMPLETE and DBT_ DEVICEARRIVAL) for each removable device when the Windows CE device is turned on.
Starting with Windows CE 3.0 it is possible to have an application run from a Compact Flash memory card when it is inserted into a device. This allows an application to auto-install from a Compact Flash card.
To set an application to be auto-run, you must place the application in aspecific folder for the CPU targeted by your application. The folder name isbased on the CPU number returned in the dwProcessorType member of theSYSTEM_INFO structure returned from calling GetSystemInfo. Table 3.7 shows the possible values and their associated constants.
Constant | Value |
---|---|
PROCESSOR_MIPS_R4000 | 4000 |
PROCESSOR_HITACHI_SH3 | 10003 |
PROCESSOR_HITACHI_SH3E | 10004 |
PROCESSOR_HITACHI_SH4 | 10005 |
PROCESSOR_MOTOROLA_821 | 821 |
PROCESSOR_SHx_SH3 | 103 |
PROCESSOR_SHx_SH4 | 104 |
PROCESSOR_STRONGARM | 2577 |
PROCESSOR_ARM720 | 1824 |
PROCESSOR_ARM820 | 2080 |
PROCESSOR_ARM920 | 2336 |
PROCESSOR_ARM_7TDMI | 70001 |
Thus, if you want your application to auto-run and the application is compiled for MIPS, you should rename your application to autorun.exe and place it in a folder called 4000, for example, 4000autorun.exe.
If your application is compiled for CEF (Common Executable Format), you should place the autorun.exe file in a folder called