In this activity a Native Code console "Hello World" application is developed a a Platform Builder subproject.
1. Load the Solution
2. Run the Subproject Wizard as above and select WCE Console Application.
3. Give the project a name (e.g. Hello) and press [Next]
Figure 14.5: Console Application Options
4. Select A typical “Hello World” Application and press [Finish]
In Solution Explorer you will see the subproject located under OS Subprojects. Expand its tree out and examine the files generated by the Wizard. For this project, the key file its source Hello.cpp. Open it in the source code editor for viewing and editing (Double-click on it in Solution Explorer). The program just writes “Hello World” to the output.
.
Figure 14.6: The generated Console Application in Solution Explorer
// Hello.cpp : Defines the entry point for the console application. // #include "stdafx.h" int _tmain(int argc, TCHAR *argv, TCHAR *envp) { _tprintf(_T("Hello World!\n")); return 0; }
// Hello.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, TCHAR *argv, TCHAR *envp)
{
_tprintf(_T("Hello World!\n"));
return 0;
}
Listing 14.1 The Hello World console application code source file.
Another important file is the sources file. Double-click on the root of the application’s subproject tree in Solution Explorer. You will see the project’s sources file which drives the projects build. It is not displayed in Solution Explorer as because it also tells the IDE what to display in the tree, as above.
RELEASETYPE=LOCAL _ISVINCPATH=$(_WINCEROOT)\public\common\sdk\inc; _OEMINCPATH=$(_WINCEROOT)\public\common\oak\inc;$(_WINCEROOT)\public\common\sdk\inc; TARGETNAME=Hello FILE_VIEW_ROOT_FOLDER= \ ReadMe.txt \ StdAfx.cpp \ prelink.bat \ postlink.bat \ FILE_VIEW_RESOURCE_FOLDER= \ FILE_VIEW_INCLUDES_FOLDER= \ StdAfx.h \ SOURCES= \ Hello.cpp \ TARGETTYPE=PROGRAM PRECOMPILED_CXX=1 TARGETLIBS= \ $(SG_OUTPUT_ROOT)\sdk\lib\$(_CPUINDPATH)\coredll.lib \ PRECOMPILED_PCH=StdAfx.pch PRECOMPILED_OBJ=StdAfx.obj PRECOMPILED_INCLUDE=StdAfx.h EXEENTRY=mainWCRTStartup POSTLINK_PASS_CMD=postlink.bat PRELINK_PASS_CMD=prelink.bat FILE_VIEW_PARAMETER_FOLDER= \ Hello.bib \ Hello.reg \ Hello.dat \ Hello.db \ ProjSysgen.bat \
RELEASETYPE=LOCAL
_ISVINCPATH=$(_WINCEROOT)\public\common\sdk\inc;
_OEMINCPATH=$(_WINCEROOT)\public\common\oak\inc;$(_WINCEROOT)\public\common\sdk\inc;
TARGETNAME=Hello
FILE_VIEW_ROOT_FOLDER= \
ReadMe.txt \
StdAfx.cpp \
prelink.bat \
postlink.bat \
FILE_VIEW_RESOURCE_FOLDER= \
FILE_VIEW_INCLUDES_FOLDER= \
StdAfx.h \
SOURCES= \
Hello.cpp \
TARGETTYPE=PROGRAM
PRECOMPILED_CXX=1
TARGETLIBS= \
$(SG_OUTPUT_ROOT)\sdk\lib\$(_CPUINDPATH)\coredll.lib \
PRECOMPILED_PCH=StdAfx.pch
PRECOMPILED_OBJ=StdAfx.obj
PRECOMPILED_INCLUDE=StdAfx.h
EXEENTRY=mainWCRTStartup
POSTLINK_PASS_CMD=postlink.bat
PRELINK_PASS_CMD=prelink.bat
FILE_VIEW_PARAMETER_FOLDER= \
Hello.bib \
Hello.reg \
Hello.dat \
Hello.db \
ProjSysgen.bat \
Listing 14.2 The Hello World console application sources file.
Warning: The may be some confusion with code source and sources file terminology. The sources file is the project file and always has that name. The code source file in this context is the .cpp file that has the project name, i.e. hello.cpp
5. Configure the subproject for development as previous.
6. Compile the application by Right-clicking on it in Solution Explorer and select Build (either).
The output is written to release directory and so can be included in the OS build if required and can also be used via Target Control when the OS runs. Click on the OS in Solution Explorer then Open the Release Directory in the Build Window. See the subproject files generated by entering dir hello.*
C:\WINCE800\OSDesigns\OSDesign6\OSDesign6\RelDir\CEPC_x86_Release>dir hello.* Volume in drive C has no label. Volume Serial Number is A08B-2FAB Directory of C:\WINCE800\OSDesigns\OSDesign1\OSDesign1\RelDir\CEPC_x86_Release 23/04/2013 04:19 PM 20,480 Hello.exe 23/04/2013 04:19 PM 21,617 Hello.map 23/04/2013 04:19 PM 839,680 hello.pdb 23/04/2013 04:19 PM 4,688 Hello.rel 4 File(s) 886,465 bytes 0 Dir(s) 59,998,638,080 bytes free
C:\WINCE800\OSDesigns\OSDesign6\OSDesign6\RelDir\CEPC_x86_Release>dir hello.*
Volume in drive C has no label.
Volume Serial Number is A08B-2FAB
Directory of C:\WINCE800\OSDesigns\OSDesign1\OSDesign1\RelDir\CEPC_x86_Release
23/04/2013 04:19 PM 20,480 Hello.exe
23/04/2013 04:19 PM 21,617 Hello.map
23/04/2013 04:19 PM 839,680 hello.pdb
23/04/2013 04:19 PM 4,688 Hello.rel
4 File(s) 886,465 bytes
0 Dir(s) 59,998,638,080 bytes free
To run the app, download and start the OS. You did not need to rebuild the OS to encompass the subproject.
1. From the Target menu, select Run Programs
2. Choose the application
3. Press [Run]
Figure 1.7: Target-Run Programs Dialog
The program will run on the target an exit, but you will probably not see the output.
4. In the source file put a breakpoint just before the application exit and rerun. You should see the output now.
Figure 14.8: Application at a breakpoint
5. Alternatively add the following before return to force user input:
TCHAR ch; _tprintf(_T("Press enter to continue:\n")); _getws(&ch);
TCHAR ch;
_tprintf(_T("Press enter to continue:\n"));
_getws(&ch);
Listing 14.3 Code to require user intervention for application to close.
Figure 1.9: Hello console application output on the target device.
6. Another way to run the application is to via Target Control (Menu Target-Target Control).At the prompt enter gi proc to see what processes are running Then enter s hello to run the program (“start” hello):
Windows CE Command Prompt : Shell commands ('?' for shell help) '.': Debugger commands ('.?' for help) '!': Debugger extension commands Ctrl-T: Terminate pending command Ctrl-L: Clear all Ctrl-A: Select all Ctrl-F: Find (F4: Search forward, Shift-F4: Search backwards) Windows CE>gi proc PROC: Name PID AcctId VMBase CurZone P00: NK.EXE 00400002 00000000 80220000 00000000 P01: shell.exe 00fc0006 00000000 00010000 00000000 P02: udevice.exe 01be0006 00000000 00010000 00000000 P03: GweUser.exe 02fb0002 00000000 00010000 00000000 P04: servicesd.exe 03220002 00000000 00010000 00000000 P05: minshell.exe 03840002 00000000 00010000 00000000 Windows CE>s hello Windows CE>
Windows CE Command Prompt
: Shell commands ('?' for shell help)
'.': Debugger commands ('.?' for help)
'!': Debugger extension commands
Ctrl-T: Terminate pending command
Ctrl-L: Clear all
Ctrl-A: Select all
Ctrl-F: Find (F4: Search forward, Shift-F4: Search backwards)
Windows CE>gi proc
PROC: Name PID AcctId VMBase CurZone
P00: NK.EXE 00400002 00000000 80220000 00000000
P01: shell.exe 00fc0006 00000000 00010000 00000000
P02: udevice.exe 01be0006 00000000 00010000 00000000
P03: GweUser.exe 02fb0002 00000000 00010000 00000000
P04: servicesd.exe 03220002 00000000 00010000 00000000
P05: minshell.exe 03840002 00000000 00010000 00000000
Windows CE>s hello
Windows CE>
7. You can also run the application directly on the target. In MinShell on the target press Command and choose Command Prompt. You now can run the application from the command line:
Figure 1.10: The MinShell on the target device.
8. Enter Hello and the application will run:
Figure 1.11: Running Hello console application directly on the target device.
Note: Applications can also be run on the device from the command prompt if prefaced by start. eg >start Hello The OS will run the application but not wait for it to end to return to the command prompt. This is useful for run applications such as WinForm apps that don’t immediately exit.
Some utilities such as ipconfig can output to the Debug tab by simply adding the /d option on the end of its command line. i.e.:
ipconfig /d
9. Try this using Target Control or Run Programs
There is a utility in the WINCEROOT tree that wrapper a command line application such as hello, run it and redirect its output to the Debug window. It’s located in:
public\common\oak\utils\debugview
Note that this folder is by default excluded from the OS build. The application we want is simply called d. Ie:
public\common\oak\utils\debugview\d
10. Explore the project contents and then build it by right-click and choose build. The output will be in relase directory
11. Try running this d application and see how to use it.
12. Then use it to redirect the output of hello to debug using:
d hello
Run Programs s d hello
1997131 PID:400002 TID:15a00e6 RELFSD: Opening file d.exe from desktop PB Debugger Loaded symbols for 'D.EXE' 1997183 PID:17900ca TID:15a00e6 RegisterDevice loading error (d will use a tmp file) 1997184 PID:17900ca TID:15a00e6 d hello PB Debugger Loaded symbols for 'HELLO.EXE' PB Debugger Unloaded symbols for 'HELLO.EXE' 1997224 PID:17900ca TID:15a00e6 Hello World! ß Output here PB Debugger Unloaded symbols for 'D.EXE' PB Debugger Unloaded symbols for 'D.EXE'
1997131 PID:400002 TID:15a00e6 RELFSD: Opening file d.exe from desktop
PB Debugger Loaded symbols for 'D.EXE'
1997183 PID:17900ca TID:15a00e6 RegisterDevice loading error (d will use a tmp file)
1997184 PID:17900ca TID:15a00e6 d hello
PB Debugger Loaded symbols for 'HELLO.EXE'
PB Debugger Unloaded symbols for 'HELLO.EXE'
1997224 PID:17900ca TID:15a00e6 Hello World! ß Output here
PB Debugger Unloaded symbols for 'D.EXE'
The text output for the application can also be directed to the IDE Debug tab using debug macros. RETAILMSG macro generates messages in both RETAIL and DEBUG OS builds and so is the most useful for application development over KITL. The first parameter is a conditional feature that if non-zero, the macro is actioned. The second parameter requires a format string expression. The WEC2013 debug macros is covered in detail in a later chapter.
13. Replace the print statement in the code as follows and remove the user input because the output will still be visible after the application closes:
int _tmain(int argc, TCHAR *argv, TCHAR *envp) { RETAILMSG(1,(_T("Hello World! "))); return 0; }
RETAILMSG(1,(_T("Hello World! ")));
Listing 1.4 Using a RETAILMSG to output to the Debug window.
14. Run the application from the IDE. A typical output is:
Run Programs s Hello 64125 PID:400002 TID:2550006 RELFSD: Opening file Hello.exe from desktop PB Debugger Loaded symbols for 'C:\WINCE800\OSDESIGNS\OSDESIGN6\OSDESIGN6\RELDIR\CEPC_X86_RELEASE\HELLO.EXE' 64154 PID:2500006 TID:2550006 Hello World! ß Output here PB Debugger Unloaded symbols for 'C:\WINCE800\OSDESIGNS\OSDESIGN6\OSDESIGN6\RELDIR\CEPC_X86_RELEASE\HELLO.EXE'
Run Programs s Hello
64125 PID:400002 TID:2550006 RELFSD: Opening file Hello.exe from desktop
PB Debugger Loaded symbols for 'C:\WINCE800\OSDESIGNS\OSDESIGN6\OSDESIGN6\RELDIR\CEPC_X86_RELEASE\HELLO.EXE'
64154 PID:2500006 TID:2550006 Hello World! ß Output here
PB Debugger Unloaded symbols for 'C:\WINCE800\OSDESIGNS\OSDESIGN6\OSDESIGN6\RELDIR\CEPC_X86_RELEASE\HELLO.EXE'
Finally, the application could also be configured to run at start up by including it in the image and using the Autolaunch tool, although that will be covered in the AutoLaunch chapter, it would be pointless for obvious reasons with this app.
NEXT: C Libraries
Click here to provide feedback and input