Run the wince application at startup

Source: Internet
Author: User

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?
  1. [HKEY_LOCAL_MACHINE/init]
  2. "Launch50" = "assumer.exe"
  3. "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:

  1. [HKEY_LOCAL_MACHINE/init]
  2. "Launch80" = "myapp.exe"
  3. "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?
  1. Int winapi winmain (hinstance, hinstance hprevinstance, lptstr lpcmdline, int ncmdshow)
  2. {
  3. Win32_find_data FD;
  4. Handle Hd = invalid_handle_value;
  5. Int icount = 20;
  6. While (icount --)
  7. {
  8. Hd =: findfirstfile (lpcmdline, & FD );
  9. Sleep (500 );
  10. If (invalid_handle_value! = HD)
  11. Break;
  12. }
  13. If (0 = icount) return 0;
  14. Findclose (HD );
  15. Shellexecuteinfo shexeinfo = {0 };
  16. Shexeinfo. cbsize = sizeof (shellexecuteinfo );
  17. Shexeinfo. fmask = see_mask_nocloseprocess;
  18. Shexeinfo. hwnd = NULL;
  19. Shexeinfo. lpverb = NULL;
  20. Shexeinfo. lpfile = lpcmdline;
  21. Shexeinfo. lpparameters = l "";
  22. Shexeinfo. lpdirectory = NULL;
  23. Shexeinfo. nshow = sw_show;
  24. Shexeinfo. hinstapp = NULL;
  25. Shellexecuteex (& shexeinfo );
  26. Return 0;
  27. }

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?
  1. While (icount --)
  2. {
  3. Hd =: findfirstfile (lpcmdline, & FD );
  4. Sleep (500 );
  5. If (invalid_handle_value! = HD)
  6. Break;
  7. }

 

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?
  1. [HKEY_LOCAL_MACHINE/init]
  2. "Launch70" = "myapp.exe"
  3. "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?
  1. [HKEY_LOCAL_MACHINE/init]
  2. "Launch50" = "myapp.exe"
  3. "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?
  1. Bool c0000topwnd: Create ()
  2. {
  3. Ishellfolder * pshf;
  4. Foldersettings FS;
  5. Rect RC;
  6. Hresult hR = e_fail;
  7. // Get a shell folder for the desktop
  8. HR = shgetdomaintopfolder (& pshf );
  9. If (HR |! Pshf)
  10. Goto cleanup;
  11. // Create a shell view for it
  12. HR = pshf-> createviewobject (null, iid_ishellview, (lpvoid *) & _ PSV );
  13. If (HR |! _ PSV)
  14. Goto cleanup;
  15. FS. viewmode = fvm_icon;
  16. FS. fflags = fwf_desktop | fwf_alignleft | fwf_noscroll;
  17. // ++ Changed by hjb
  18. // Set the size of the desktop window to 0
  19. // Setrect (& rc, 0, 0, getsystemmetrics (sm_cxvirtualscreen), getsystemmetrics (sm_cyvirtualscreen ));
  20. Setrect (& rc, 0, 0, 0, 0 );
  21. // -- Changed by hjb
  22. // Create the desktop's View window (no need to addref since createviewwindow does it)
  23. HR = _ PSV-> createviewwindow (null, & FS, (ishellbrowser *) This, & rc, & _ hwnd );
  24. If (HR |! _ Hwnd)
  25. {
  26. Release ();
  27. Goto cleanup;
  28. }
  29. Registerdesktop (_ hwnd );
  30. Cleanup:
  31. If (pshf)
  32. Pshf-> release ();
  33. Return (hR = s_ OK );
  34. }

 

C:/wince600/public/Shell/oak/HPC/Explorer/main/explorer. cpp

 

View plaincopy to clipboardprint?
  1. DWORD winapi createtaskbar (lpvoid pevent)
  2. {
  3. Handle hsyncevent = * (handle *) pevent );
  4. Ctaskbar * ptaskbar = NULL;
  5. Hwnd hwndtb = NULL;
  6. Ptaskbar = new ctaskbar;
  7. // ++ Added by hjb
  8. // Force termination upon Task Bar Creation
  9. If (ptaskbar)
  10. {
  11. Delete ptaskbar;
  12. Setevent (hsyncevent );
  13. Return 0;
  14. }
  15. // -- Added by hjb
  16. If (! Ptaskbar)
  17. {
  18. Setevent (hsyncevent );
  19. Return 0;
  20. }
  21. G_taskbar = ptaskbar;
  22. If (! Ptaskbar-> Register (g_hinstance ))
  23. {
  24. G_taskbar = NULL;
  25. Delete ptaskbar;
  26. Setevent (hsyncevent );
  27. Return 0;
  28. }
  29. Registertaskbar (ptaskbar-> getwindow ());
  30. Setevent (hsyncevent );
  31. DWORD dwret = ptaskbar-> messageloop ();
  32. Delete ptaskbar;
  33. Return dwret;
  34. }

 

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

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.