270 likes | 407 Views
Module 3: Preparing an Application Development Environment. Overview. Exporting an SDK from Platform Builder Importing an SDK Win32 Programming Primer. Exporting an SDK from Platform Builder. Need for an SDK The Exporting Process. Need for an SDK. Platform Builder. Custom SDK.
E N D
Overview • Exporting an SDK from Platform Builder • Importing an SDK • Win32 Programming Primer
Exporting an SDK from Platform Builder • Need for an SDK • The Exporting Process
Need for an SDK Platform Builder Custom SDK Windows CE Toolkits Windows CE OS configuration Libraries Toolkits for Visual C++ Header files Run-time libraries Help files OAL Runtime files Device drivers Platform extension Toolkits for Visual Basic Platform Manager components
The Exporting Process • You Must Build A Platform Before Exporting an SDK • Menu : Platform/Export SDK • Choose Add-on technologies (MFC, ATL, Console application) • Select configuration • Check Platform Manager Transport Layer
Importing an SDK • Importing to Embedded Visual C++ • Importing to Embedded Visual Basic • Using the Platform Manager
Importing to Embedded Visual C++ • Decompress SDK into \Windows CE Tools directory • Run Embedded Visual C++ • Select File | New… then [Projects] tab • Select Active WCE Configuration on WCE Configuration Toolbar. • Example:
Importing to Embedded Visual Basic • Decompress SDK into \Windows CE Tools directory • Run Embedded Visual Basic • Select File | New Project • On New Project Window, Select: • Windows CE Formless Project • Platform-Specific Project
Using Platform Manager • Platform Manager manages the interaction between desktop and target platform • Operates with toolkits (Visual C++, Visual Basic) to download applications • Connects target platform with remote tools • Target-side and host-side components • The target side - built by Platform Builder in your Windows CE image • The host side - created by toolkits with the exported custom SDK
Win32 Programming Primer • Creating a Win32 Application • Useful Win32 Functions • The Unicode Character Set • Processes and Threads • Structured Exception Handling
Useful Win32 Functions • MessageBox – Displays message window • Example: MessageBox(NULL, _T("Hello"), _T("Title"), 0); • NKDbgPrintfW – Format & debug output • Example: NKDbgPrintfW(_T("Value is %d\n\r"), iVal);
Unicode - Compiler Support • ANSI Characters and Strings: • ‘H’ • “Hello Unicode” • ==> Store as ‘char’ or ‘unsigned char’ • Unicode Characters and Strings: • L’H’ • L”Hello Unicode” • ==> Store as “short’ or ‘unsigned short’ • Bi-Modal (_UNICODE) • TEXT(‘H’) • TEXT(“Hello Unicode”)
Unicode - Data Types • ANSI • CHAR - resolves to char • LPSTR - resolves to char * • Unicode • WCHAR - resolves to unsigned short • LPWSTR - resolves to unsigned short * • Bi-Modal (_UNICODE) • TCHAR - resolves to char or unsigned short • LPTSTR - resolves to char * or unsigned short *
Unicode - C-Runtime Functions • ANSI • strlen() - query length • strcpy() - copy string • strcat() - concatenate string • Unicode • wcslen() - query length • wcscpy() - copy string • wcscat() - concatenate string • Bi-Modal (_UNICODE) • _tcslen() - query length • _tcscpy() - copy string • _tcscat() - concatenate string
Unicode - C-Runtime Conversion Functions • Converting to Unicode • mbstowcs( • wchar_t*wcstr, // Output string. • constchar*mbstr, // Input string. • size_tcount); // Character count. • Converting From Unicode • wcstombs( • char*mbstr, // Output string. • constwchar_t*wcstr, // Input string. • size_tcount); // Character count.
Processes and Threads • Processes • Maximum 32 processes can be loaded at the same time • Support for console applications • Threads • Smallest unit of execution • Number of threads only limited by available memory • Preemptive priority-based scheduling (256 priorities) • Quantum default length is 100ms (configurable)
Processes and Threads - Creating a Process CreateProcess( LPCTSTR lpszImageName, // EXE file name LPCTSTR lpszCmdLine, // Parameters LPSECURITY_ATTRIBUTES lpsaProcess, // = NULL LPSECURITY_ATTRIBUTES lpsaThread, // = NULL BOOL fInheritHandles, // Windows CE requires FALSE DWORD dwFlags, // See docs for details LPVOID lpEnvironment, // = NULL LPTSTR lpszCurDir, // Startup directory // = NULL LPSTARTUPINFO lpStart, // = NULL LPPROCESS_INFORMATION lppi); // Return handles
Slot 32 Slot 31 Slot 30 . . . Slot 3 Slot 2 Slot 1 Slot 0 private.dll shared.dll coredll.dll App.Exe 64K NML Processes and Threads –System and Process Memory 1G 0 32M Address Space
Processes and Threads - Thread API • Creating Threads: • CreateThread (Win32) • Suspending Threads: • SuspendThread (Win32) • ResumeThread (Win32) • Destroying Threads: • ExitThread (Win32) • TerminateThread (Win32)
Structured Exception Handling - Exception Syntax __try { // Protected block. } __except (/* filter */ ) { // Exception handler. }
Structured Exception Handling - The Filter // hard code a value __except (EXCEPTION_EXECUTE_HANDLER) __try { ... ... ... ... ... ... } __except ( ) { ... ... ... ... ... ... } // expression __except((GetExceptionCode()== EXCEPTION_ACCESS_VIOLATION) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) // call a function __except (CheckIt(GetExceptionCode()) ... int CheckIt (DWORD dwCode) { switch (dwCode) { case xxxx:... } return EXCEPTION_EXECUTE_HANDLER; }
Structured Exception Handling - Exception API • Create an exception VOID RaiseException(dwCode, dwFlags, cArgs, lpArgs) • Query exception DWORD GetExceptionCode (VOID) • Query abnormal termination BOOL AbnormalTermination (VOID) • Query exception information LPEXCEPTION_POINTERS GetExceptionInformation (void)
Review • Exporting an SDK from Platform Builder • Importing an SDK • Win32 Programming Primer