Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
In this walkthrough you will create, build and run a simple Hello World application in C++.
To create a Windows Application project
-
On the Filemenu, point to New, and then select Project.
-
In the Project Typespane, expand the Visual C++branch and select Smart Device.
-
In the Templatespane, choose Win32 Smart Device Project.
-
In the Namebox, name the project something unique to indicate the application's purpose. In the Locationbox, enter the directory in which you want to save your project, or click the Browsebutton to navigate to it. Select OK.
-
The Win32 Smart Device Project Wizard will appear. Select Nextto select the platforms you wish to support.
-
Select the platforms you wish to support with your application. For this walkthrough, select a Windows Mobile 6 or higher SDK and add it to the Selected SDKs. Remove any other platforms from the Selected SDKslist. Select Next.
-
This step of the wizard allows you to select additional Application Settings. Make sure Windows Applicationis selected and then click Finish.
The Win32 Smart Device Projectwill be created and the .cpp file will be displayed in the IDE.
To compile and link the application
-
Replace the WM_PAINT event handler with the following lines of code:
Copy Code case WM_PAINT: hdc = BeginPaint(hWnd, &ps); int bReturn; TCHAR szHelloStr[50]; StringCchCopy(szHelloStr, 50, L"Hello World!"); // Set text color. SetTextColor (hdc, RGB(0,0,0)); bReturn = ExtTextOut (hdc, 10, 10, 0, NULL, szHelloStr, lstrlen(szHelloStr), NULL); EndPaint(hWnd, &ps); break;
-
From the Solution Configurationsdropdown, located in the toolbar, select Debug.
-
From the Target Devicedropdown, located in the toolbar, select your device to test the application on. For this walkthrough, select Windows Mobile 6 Classic Emulator.
-
Build your project by selecting Build Solutionfrom the Buildmenu. Check the results of the build in the Outputwindow. Fix errors as needed until the project builds successfully.
To run and debug the application
-
Set your desired breakpoints. You can set a breakpoint by clicking in the left margin of the line of code you want to set the breakpoint on or by placing the cursor on a line of code and selecting Toggle Breakpointfrom the Debugmenu. F9will also toggle breakpoints.
-
Select Connect to Devicefrom the Toolsmenu to set up communication with the debugging device, in this case the Windows Mobile 6 Classic Emulator. Click the Connectbutton.
-
The emulator window will open and start up. It may take a minute or so to set up the connection with the emulator. Click Closeon the Connectingdialog when the connection has been successfully made.
-
Select Start Debuggingfrom the Debugmenu or press F5to start the application. The executable and any other needed files will be transferred to the emulator. It may take a minute or so to transfer the files.
-
You can now run your program on the target device and debug it in the Visual Studio environment. You can use the Continue (F5), Step Over (F10), Step Into (F11), and Step Out (Shift+F11)commands to walk through the code.
-
To stop debugging, you can exit your application or select Stop Debugging (Shift+F5)from the Debugmenu.
-
When you are ready to build the release version of your project, you can change the Solution Configurationdropdown to Releaseand rebuild the project to build the release version.
-
When you close the emulator, you are given the option to save the emulator state. By saving the state, you can decrease the emulator start up time the next time you launch the emulator.