Microsoft Visual C++/CLI Step by Step

Book description

Your hands-on guide to Visual C++/CLI fundamentals

Expand your expertise—and teach yourself the fundamentals of the Microsoft Visual C++/CLI language. If you have previous programming experience but are new to Visual C++, this tutorial delivers the step-by-step guidance and coding exercises you need to master core topics and techniques.

Discover how to:

  • Write and debug object-oriented C++ programs in Visual Studio 2012

  • Utilize the various features of the C++/CLI language

  • Make use of the Microsoft .NET Framework Class Library

  • Create a simple Windows Store app

  • Use .NET features such as properties, delegates and events

  • Access data from disparate sources using ADO.NET

  • Create and consume web services using Windows Communication Foundation

  • Work effectively with legacy code and COM

  • Table of contents

    1. Dedication
    2. Introduction
      1. Who should read this book
        1. Assumptions
      2. Who should not read this book
      3. Organization of this book
        1. Finding your best starting point in this book
      4. Conventions and features in this book
      5. System requirements
      6. Code samples
      7. Acknowledgments
      8. Errata and book support
      9. We want to hear from you
      10. Stay in touch
    3. I. Getting Started with C++ .NET
      1. 1. Hello C++!
        1. What is C++/CLI?
        2. Your first C++/CLI application
          1. The main function
          2. C++ keywords and identifiers
        3. Creating an executable application—theory
          1. Editing the application source files
          2. Compiling the source files
          3. Running and testing the application
        4. Creating an executable application—practice
          1. Creating a project
          2. Editing the C++ source code
          3. Building the executable
          4. Executing the application
        5. Conclusion
        6. Quick reference
      2. 2. Introducing Object-Oriented Programming
        1. What is object-oriented programming?
        2. Features of object-oriented programming languages
          1. Encapsulation
          2. Inheritance
          3. Polymorphism
        3. Classes and objects
        4. Benefits to the development life cycle
        5. A simple example
        6. Quick reference
      3. 3. Variables and Operators
        1. What is a variable?
        2. The fundamental data types
        3. Declaring a variable
          1. Variable naming
        4. Declaring multiple variables
        5. Assigning values to variables
        6. Handles and pointers
        7. Arrays
        8. Constants
        9. Typedefs
        10. The .NET Framework String class
        11. Operators and expressions
          1. Assignment operators
          2. Arithmetic operators
          3. Relational and logical operators
          4. Bitwise operators
          5. The ternary operator
          6. Type casting
          7. Operator precedence and associativity
        12. Quick reference
      4. 4. Using Functions
        1. Declaring function prototypes
          1. Declaring a simple function prototype
          2. Declaring parameters in a function prototype
          3. Declaring the return type in a function prototype
          4. Declaring default values for function parameters
          5. Defining function bodies
            1. Defining a simple function body
            2. Defining a function body that uses parameters
            3. Defining a function body that returns a value
          6. Calling functions
            1. Calling functions in the sample application
          7. Stepping through the application by using debugger
          8. Understanding local and global scope
            1. Overloading functions
        2. Quick reference
      5. 5. Decision and Loop Statements
        1. Making decisions by using the if statement
          1. Performing one-way tests
          2. Performing two-way tests
          3. Performing multiway tests
          4. Performing nested tests
        2. Making decisions by using the switch Statement
          1. Defining simple switch statements
          2. Using fall-through in a switch statement
        3. Performing loops
          1. Using while loops
          2. Using for loops
          3. Using do-while loops
          4. Performing unconditional jumps
        4. Quick reference
      6. 6. More About Classes and Objects
        1. Organizing classes into header files and source files
          1. Declaring a class in a header file
          2. Implementing a class in a source file
        2. Creating objects
        3. Initializing objects by using constructors
          1. Defining constructors
          2. Member initialization lists
        4. Defining class-wide members
          1. Defining class-wide data members
          2. Defining class-wide member functions
          3. Class constructors
        5. Using constants in classes
          1. Using class-wide constants
          2. Using instance constants
        6. Defining object relationships
          1. Defining the LoyaltyScheme Class
          2. Implementing the LoyaltyScheme class
          3. Creating and using LoyaltyScheme objects
          4. Testing the application
        7. Quick reference
      7. 7. Controlling Object Lifetimes
        1. The .NET approach to object lifetimes
        2. Destruction and finalization
          1. Destructors
          2. Finalizers
            1. A few points about finalizers
          3. Implementing the destructor and finalizer for a class
            1. Using the finalizer
            2. Using the destructor
          4. Objects and stack semantics
            1. Traditional C++ object creation and destruction
            2. Creating objects with stack semantics
          5. Copy constructors
          6. Relating objects with stack semantics
            1. When to use handles?
        3. Quick reference
      8. 8. Inheritance
        1. What is inheritance?
          1. Inheritance terminology
          2. Inheritance and code reuse
        2. Designing an inheritance hierarchy
          1. A word on substitutability
        3. Defining a base class
        4. Defining a derived class
        5. Creating derived class objects
        6. Concrete and abstract classes
        7. Overriding member functions
        8. Protected access
        9. Defining sealed classes
          1. Abstract and sealed
        10. Defining and using interfaces
        11. Quick reference
    4. II. Microsoft .NET Programming Basics
      1. 9. Value Types
        1. Reference types and value types
          1. The need for value types
          2. Properties of value types
        2. Structures
          1. Creating and using a simple struct
          2. Investigating the structure
          3. The differences between structures and classes
          4. Implementing constructors for a structure
          5. Using one structure within another
          6. Copying structures
        3. Enumerations
          1. Creating and using an enumeration
            1. More about enumerations
          2. Using enumerations in applications
          3. Using memory efficiently
        4. Quick reference
      2. 10. Operator Overloading
        1. What is operator overloading?
          1. What types need overloaded operators?
          2. What can you overload?
          3. Rules of overloading
        2. Overloading operators in managed types
          1. Overloading arithmetic operators
          2. Using static operator overloads
          3. What functions can you overload?
          4. Implementing logical operators
            1. Implementing Equals
          5. Implementing increment and decrement
          6. Operators and reference types
          7. Guidelines for providing overloaded operators
        3. Quick reference
      3. 11. Exception Handling
        1. What are exceptions?
          1. How do exceptions work?
          2. Exception types
        2. Throwing exceptions
        3. Handling exceptions
          1. Using the try and catch construct
          2. Customizing exception handling
          3. Using the exception hierarchy
          4. Using exceptions with constructors
          5. Nesting and rethrowing exceptions
          6. The finally block
          7. The catch(…) block
        4. Creating your own exception types
        5. Using safe_cast for dynamic casting
        6. Using exceptions across languages
        7. Quick reference
      4. 12. Arrays and Collections
        1. Native C++ arrays
          1. Passing arrays to functions
          2. Initializing arrays
          3. Multidimensional arrays
          4. Dynamic allocation and arrays
        2. Generic types
        3. Managed arrays
          1. Initialization
            1. Initialization
            2. Arrays and reference types
            3. Using the for each loop with arrays
            4. Multidimensional arrays
        4. The .NET array class
          1. Basic operations on arrays
          2. More advanced array operations
            1. Copying array elements
            2. Searching
            3. Sorting
          3. Using enumerators
        5. Other .NET collection classes
          1. The List<T> class
            1. Other list operations
          2. The SortedList<K,V> class
            1. Other SortedList operations
        6. Generics and templates
          1. The STL/CLR library
            1. The three concepts behind STL
        7. Quick reference
      5. 13. Properties
        1. What are properties?
          1. The two kinds of properties
        2. Implementing scalar properties
          1. Errors in properties
          2. Auto-implemented properties
          3. Read-only and write-only properties
          4. Properties, inheritance, and interfaces
        3. Implementing indexed properties
          1. The Bank example
            1. Implementing the Bank class
            2. Adding the Account class
          2. Creating Account class properties
        4. Adding accounts to the Bank class
          1. Implementing the Add and Remove methods
          2. Implementing an indexed property to retrieve accounts
        5. Quick reference
      6. 14. Delegates and Events
        1. What are delegates?
        2. What is the purpose of delegates?
          1. Defining delegates
          2. Implementing delegates
            1. Calling static member functions by using delegates
            2. Calling non-static member functions by using delegates
            3. Using multicast delegates
            4. Delegates that return a result
        3. What are events?
          1. Implementing an event source class
          2. Implementing an event receiver
          3. Hooking it all together
            1. Standard events and System::EventHandler
        4. Quick reference
      7. 15. The .NET Framework Class Library
        1. What is the .NET Framework?
          1. The Common Language Runtime
          2. The Microsoft Intermediate Language
          3. The Common Type System
          4. The Common Language Specification
          5. The .NET Framework class library
          6. Assemblies
          7. Metadata
        2. The .NET Framework namespaces
          1. Using namespaces in C++ applications
          2. The System namespace
            1. Basic types
            2. Floating-point types
          3. The Collections namespaces
          4. The Collections interfaces
          5. The Diagnostics namespace
          6. The IO namespace
          7. The Windows namespaces
          8. The Net namespaces
          9. The ServiceModel namespaces
          10. The Xml namespaces
          11. The Data namespaces
          12. The Web namespaces
        3. Quick reference
    5. III. Using the .NET Framework
      1. 16. Working with Files
        1. The System::IO namespace
        2. Implementing text I/O by using readers and writers
          1. Using TextWriter
          2. The FileStream class
          3. Using TextReader
        3. Working with files and directories
          1. Getting information about files and directories
        4. Binary I/O
          1. The BinaryWriter class
          2. The BinaryReader class
        5. Quick reference
      2. 17. Reading and Writing XML
        1. XML and .NET
          1. The .NET XML namespaces
          2. The XML processing classes
        2. Parsing XML by using XmlReader
          1. Creating XmlReaders
            1. Creating XmlReaders
            2. The XmlReaderSettings class
            3. Verifying well-formed XML
            4. Handling attributes
          2. Parsing XML with validation
        3. Writing XML by using XmlTextWriter
        4. Using XmlDocument
          1. What is the W3C DOM?
          2. The XmlDocument class
          3. The XmlNode class
        5. Quick reference
      3. 18. Using ADO.NET
        1. What is ADO.NET?
          1. ADO.NET data providers
            1. Provider-independent code
          2. ADO.NET namespaces
          3. ADO.NET assemblies
        2. Creating a connected application
          1. Connecting to a database
          2. Creating and executing a command
          3. Executing a command that modifies data
          4. Executing queries and processing the results
        3. Creating a disconnected application
        4. Disconnected operation using a DataSet
        5. Quick reference
      4. 19. Writing a Service by Using Windows Communication Foundation
        1. What is Windows Communication Foundation?
          1. Distributed systems
          2. Services
            1. Characteristics of services
          3. Connectivity
        2. The ABCs of WCF
          1. Endpoints
          2. Address
            1. Base addresses
            2. Metadata Exchange addresses
          3. Binding
          4. Contract
          5. Message exchange patterns
          6. Behaviors
        3. Creating a service
          1. Writing a service client
          2. Adding metadata to the service
          3. Accessing a service by using a proxy
            1. Creating the wrapper DLL
            2. Using the wrapper
        4. Quick reference
      5. 20. Introducing Windows Store Apps
        1. A (brief) history of writing Windows user interface applications
          1. The Win32 API
          2. Microsoft Foundation Classes
          3. Windows Forms
          4. Windows Presentation Foundation
          5. Windows 8 and Windows Store
          6. Which UI library to choose?
        2. Introducing Windows Store apps
          1. Main features of Windows Store apps
            1. App behavior
            2. Hardware usage
            3. The UI model
            4. Contracts and charms
            5. The WinRT APIs
        3. Writing a Windows Store app
          1. Creating your first Windows Store app
          2. Examining the project
        4. Introducing XAML
          1. What is XAML?
          2. XAML syntax
          3. XAML controls
          4. Layout controls
          5. Event handling
        5. C++/CX and Windows RT
          1. Windows RT
          2. Metadata
          3. C++/CX syntax
            1. Classes
            2. Generics
            3. Strings
          4. Common namespaces
            1. The Windows namespaces
            2. The Platform namespaces
        6. Quick reference
      6. 21. More About Windows Store Apps
        1. Building the basic calculator
          1. Laying out the number buttons
          2. Handling number input
          3. Adding arithmetic operations
            1. Adding the arithmetic buttons
            2. Getting the number
            3. Remembering the operation
          4. Performing calculations
            1. Adding the handler and getting the number
            2. Performing the arithmetic operation
          5. Testing the calculator
          6. Improving the graphics
            1. Creating and using a tile
          7. Handling different number bases
            1. Adding the hexadecimal and base buttons
            2. Changing the base
            3. Converting the string in the display
          8. Using app bars
            1. Defining the button styles
            2. Adding an app bar
            3. Hooking it up
          9. Adding sharing
            1. Contracts and charms
            2. Implementing sharing
            3. The DataPackage class
            4. Handling share requests
          10. Where next?
        2. Quick reference
    6. IV. Advanced topics
      1. 22. Working with Unmanaged Code
        1. Managed vs. unmanaged code
          1. Mixed classes
          2. The GCHandle type
        2. Pinning and boxing
          1. Interior pointers
          2. Pinning pointers
          3. Boxing and unboxing
          4. Boxing
          5. Unboxing
        3. Using P/Invoke to call functions in the Win32 API
          1. The DllImportAttribute class
          2. Passing structures
        4. Quick reference
      2. 23. Attributes and Reflection
        1. Metadata and attributes
          1. Using ILDASM
        2. Using predefined attributes
          1. The AssemblyInfo.cpp file
          2. Using the predefined attribute classes
        3. Defining your own attributes
          1. Attribute class properties
          2. Design criteria for attribute classes
          3. Writing a custom attribute
        4. Using reflection to obtain attribute data
          1. The Type class
          2. Accessing standard attributes
          3. Accessing custom attribute data
        5. Quick reference
      3. 24. Living with COM
        1. COM components and the COM Interop
        2. Using COM components from .NET code
          1. How do RCWs work?
          2. Creating and using RCWs
          3. Handling COM errors
          4. Late binding to COM objects
        3. Using .NET components as COM components
          1. What must .NET types implement to be used as COM objects?
        4. Quick reference
    7. Index
    8. About the Author
    9. Copyright

    Product information

    • Title: Microsoft Visual C++/CLI Step by Step
    • Author(s): Julian Templeman
    • Release date: August 2013
    • Publisher(s): Microsoft Press
    • ISBN: 9780735675162