Another method for automatically running the wince application upon startup
Keyword: wince Automatic Running
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 the application and application shortcuts to the image, and then add the shortcuts to the startup directory so that the application can run automatically after the system runs;
2. Replace the shell of Wince directly, that is, modify the registry:
[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 and modify the registry:
[HKEY_LOCAL_MACHINE/init]
"Launch80" = "myapp.exe"
"Depend80" = HEX: 1E, 00
You can set the startup sequence and dependencies;
All of the above methods are feasible, but there is a problem, that is, the application is integrated into NK, that is, every time the application is upgraded, It is very troublesome to re-compile and download the kernel, especially in the program debugging stage, we all want 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 achieve this, modify the "launch80" = "myapp.exe" to "launch80" = "/stdcard/myapp.exe" (volume file. 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:
int WINAPI WinMain(HINSTANCE 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;
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 NK 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.
Address: http://blog.csdn.net/lanruoshui/archive/2007/05/23/1622263.aspx