I. general methods for self-running upon startup [reprinted]
Recently, during the development process, I encountered an issue where the wince application runs automatically when it starts up. I searched for it online and found that there are three possible methods:
1,Add application and application shortcuts to the imageAnd then add the shortcut to the startup directory so that the application can run automatically after the system runs;
2,Replace the shell of Wince directlyTo modify the registry:
View plaincopy to clipboardprint?
- [HKEY_LOCAL_MACHINE/init]
- "Launch50" = "assumer.exe"
- "Depend50" = HEX: 14,00, 1e, 00
Change this assumer.exe to your application (for example, myapp.exe );
3,Add the application to the image, Modify the registry:
- [HKEY_LOCAL_MACHINE/init]
- "Launch80" = "myapp.exe"
- "Depend80" = HEX: 1E, 00
You can set the startup sequence and dependencies. This is to set the startup sequence. The larger the number after launch is, the more dependent it is to start. The specified dependency item after depend80 is in hexadecimal format, the preceding statement indicates that the dependent items are the gwes.exe defined in the device.exeand launch30defined by launch20. Note that the number range after launch is 0 to 99, and those beyond this range will not be effective.
All of the above methods are feasible, but there is a problem:Applications are integrated into NK.That is to say, every time you upgrade the application, you have to re-compile and download the kernel, which is very troublesome. Especially in the program debugging stage, everyone wants to put the application on the SD card, so it is easier to update it;
It is said that the third method can be used to modify "launch80" = "myapp.exe"
Is "launch80" = "/stdcard/myapp.exe" (stdcard is the SD card directory ),
However, I tried it but it failed because the file driver of the SD card was not loaded yet when launch80 was running,
The myapp.exe file cannot be found. Similarly, applications in the SD card cannot be loaded using shortcuts.
I have compiled a small program, such as shellexe.exe, to add this program to the image, and call shellexe using the startup shortcut. The specific implementation steps are as follows:
1. Compile the following code in EVC:
View plaincopy to clipboardprint?
- Int winapi winmain (hinstance, hinstance hprevinstance, lptstr lpcmdline, int ncmdshow)
- {
- Win32_find_data FD;
- Handle Hd = invalid_handle_value;
- Int icount = 20;
- While (icount --)
- {
- Hd =: findfirstfile (lpcmdline, & FD );
- Sleep (500 );
- If (invalid_handle_value! = HD)
- Break;
- }
- If (0 = icount) return 0;
- Findclose (HD );
- Shellexecuteinfo shexeinfo = {0 };
- Shexeinfo. cbsize = sizeof (shellexecuteinfo );
- Shexeinfo. fmask = see_mask_nocloseprocess;
- Shexeinfo. hwnd = NULL;
- Shexeinfo. lpverb = NULL;
- Shexeinfo. lpfile = lpcmdline;
- Shexeinfo. lpparameters = l "";
- Shexeinfo. lpdirectory = NULL;
- Shexeinfo. nshow = sw_show;
- Shexeinfo. hinstapp = NULL;
- Shellexecuteex (& shexeinfo );
- Return 0;
- }
Generate the executable file of shellexe.exe. The main function of this code segment is to find the specified application and execute it. The following Code ensures that the application is executed only after the SD card file system is correctly loaded;
View plaincopy to clipboardprint?
- While (icount --)
- {
- Hd =: findfirstfile (lpcmdline, & FD );
- Sleep (500 );
- If (invalid_handle_value! = HD)
- Break;
- }
The file name and path are specified by the command line parameters:
Shexeinfo. lpfile = lpcmdline;
2. Create a shortcut, such as Autorun. lnk, and edit the content as follows:
21 #/Windows/shellexe.exe/stdcard/myapp.exe
The absolute path of the/stdcard/myapp.exe application;
3. Add myapp.exe and autorun. lnk to NK by adding the following content to the project. bib file:
Shellexe.exe F:/wince420/pbworkspaces/lioetenter/reldir/shellexe.exe NK sautorun. lnk F:/wince420/pbworkspaces/lioetenter/reldir/Autorun. lnk s
Note: the attribute of shellexe.exe cannot contain H (hidden ).
4. Add the following content to project. DAT:
Directory ("/Windows/startup"):-file ("autorun. lnk", "/Windows/Autorun. lnk ")
5. Select make image (((of course, buildcan also be used. Click "Flash" and run the program. You can see that the myapp.exe file of the SDK is correctly executed.
Summary
This scheme is convenient to use. shellexe.exe does not need to be re-compiled every time. You only need to modify Autorun. lnk according to the application path, and can load applications in flash, USB flash drive, and SD card. You do not need to re-run the kernel after debugging and upgrading the application.
Ii. Start up and run the MFC Program
Running a customized shell at the startup of Wince is a basic requirement of many systems. Sometimes, you need to shield the shell that comes with wince. There are generally two methods for self-starting programs in wince: modifying the registry and adding a self-starting shortcut. It is convenient to modify the Registry as follows:
View plaincopy to clipboardprint?
- [HKEY_LOCAL_MACHINE/init]
- "Launch70" = "myapp.exe"
- "Depend70" = HEX: 14,00, 1e, 00
You only need to package myapp.exe to NK and add the above registry information to platform. Reg. This will automatically run the program when wince starts. However, wince's shellalways comes first and then runs myapp.exe. To avoid this situation, we can modify the registry settings as follows:
View plaincopy to clipboardprint?
- [HKEY_LOCAL_MACHINE/init]
- "Launch50" = "myapp.exe"
- "Depend50" = HEX: 14,00, 1e, 00
Replace the value of the original assumer.exewith myapp.exe. In this example, the customized shellers are directly entered during wincestartup, but the assumer.exe is not started. However, a new problem may be introduced. If the customized shell is written based on MFC and the class library such as cfiledialog is used, unexpected situations will occur, as shown in:
The figure shows the status of the file in the registration table when you do not start assumer.exe, but there is no problem when you start assumer.exe. This description indicates that cfiledialogdepends on assumer.exe in a specific process. The details are not studied. However, if assumer.exe is not started, an issue may occur when the MFC-based shell runs. The specified cmd.exe must be started, but the wince interface cannot appear. To solve this problem, you need to modify assumer.exe. In wince5.0 and wince6.0, this part of code is public. In wince6.0, shell-related code is in the C:/wince600/public/Shell/oak/HPC/Explorer/main directory.
After reading this part of code, we found that we only need to modify the following two files to meet the requirements.
C:/wince600/public/Shell/oak/HPC/Explorer/main/desktop. cpp
View plaincopy to clipboardprint?
- Bool c0000topwnd: Create ()
- {
- Ishellfolder * pshf;
- Foldersettings FS;
- Rect RC;
- Hresult hR = e_fail;
- // Get a shell folder for the desktop
- HR = shgetdomaintopfolder (& pshf );
- If (HR |! Pshf)
- Goto cleanup;
- // Create a shell view for it
- HR = pshf-> createviewobject (null, iid_ishellview, (lpvoid *) & _ PSV );
- If (HR |! _ PSV)
- Goto cleanup;
- FS. viewmode = fvm_icon;
- FS. fflags = fwf_desktop | fwf_alignleft | fwf_noscroll;
- // ++ Changed by hjb
- // Set the size of the desktop window to 0
- // Setrect (& rc, 0, 0, getsystemmetrics (sm_cxvirtualscreen), getsystemmetrics (sm_cyvirtualscreen ));
- Setrect (& rc, 0, 0, 0, 0 );
- // -- Changed by hjb
- // Create the desktop's View window (no need to addref since createviewwindow does it)
- HR = _ PSV-> createviewwindow (null, & FS, (ishellbrowser *) This, & rc, & _ hwnd );
- If (HR |! _ Hwnd)
- {
- Release ();
- Goto cleanup;
- }
- Registerdesktop (_ hwnd );
- Cleanup:
- If (pshf)
- Pshf-> release ();
- Return (hR = s_ OK );
- }
C:/wince600/public/Shell/oak/HPC/Explorer/main/explorer. cpp
View plaincopy to clipboardprint?
- DWORD winapi createtaskbar (lpvoid pevent)
- {
- Handle hsyncevent = * (handle *) pevent );
- Ctaskbar * ptaskbar = NULL;
- Hwnd hwndtb = NULL;
- Ptaskbar = new ctaskbar;
- // ++ Added by hjb
- // Force termination upon Task Bar Creation
- If (ptaskbar)
- {
- Delete ptaskbar;
- Setevent (hsyncevent );
- Return 0;
- }
- // -- Added by hjb
- If (! Ptaskbar)
- {
- Setevent (hsyncevent );
- Return 0;
- }
- G_taskbar = ptaskbar;
- If (! Ptaskbar-> Register (g_hinstance ))
- {
- G_taskbar = NULL;
- Delete ptaskbar;
- Setevent (hsyncevent );
- Return 0;
- }
- Registertaskbar (ptaskbar-> getwindow ());
- Setevent (hsyncevent );
- DWORD dwret = ptaskbar-> messageloop ();
- Delete ptaskbar;
- Return dwret;
- }
After these two changes, compile the directory first, and then re-compile the entire system (execute sysgen. Explorer.exe is still started and can still hear the sound of Wince startup, but the wince interface has been blocked. In this case, the MFC-based shell can also work normally, as shown in:
In practice, I did not complete this test by modifying the source code compilation. When compiling the C:/wince600/public/Shell/oak/HPC/Explorer/main directory, only explorer. Lib is generated. It takes too long to re-compile the entire system, so that the file of assumer.exe under the project directory is directly modified and tested after makeimg. There should be a quick compilation method here, but I don't know how to do it now.
After the modification, it was tested in the simulator of wince6.0 to achieve the expected effect. In this case, the contradiction between shelland assumer.exe Based on mfcis almost solved. It is not clear whether there are any hidden risks. At present, it seems that there is no problem.
In addition, you must back up the files in the Public and Private directories to avoid future problems.
From: http://blog.csdn.net/linsi/archive/2010/04/12/5475456.aspx