Course Notes
Computer Engineering

Sample Code from Course Directories

Organized by Course

Blocking Queue Code
Blocking Queue Code Snippet

"Just because you can doesn't mean you should."
"The Single Responsibility Principle trumps everything else"

This page is partially updated - more changes to come soon.

Most of the code linked on pages of this site has been developed with Visual Studio. I am now using Visual Studio 2015 so you will need this latest version to build a lot of the code here. You can download the Visual Studio Community Edition here. It's free. The community edition requires about 400 Mb of unused disk space.

If you are a matriculated student you can download the Enterprise Edition at no cost from Dreamspark using your SU credentials. The Enterprise Edition requires about 3 Gb of unused disk space.

Both editions provide all of the features you need for my courses.

Code Organized by Topic


Courses:

Core Technologies, Software Modeling & Analysis, Internet Programming, Object Oriented Design, Distributed Objects, Design Patterns


Core Technologies:

The code in this group is relevant to more than one of the courses covered by these notes, especially CSE681 - Software Modeling and Analysis and CSE687 - Object Oriented Design.

Native C++, C++/CLI, C#, Sockets, WCF, Threads & Synch, Windows Programming, WPF

CT-Top Top

Native C++

Alias Demo
Aliases used in Symbol Table definition

Callable Objects
Demonstration of functions, function pointers, functors, and lambdas

Chrono Timer
Definition of high resolution timer using the std::chrono library

Blocking queue
Threadsafe blocking queue using std::queue, std::condition_variable and std::mutex

C++ Threads and Locks
Demonstration of C++11 threads and locks

Concurrent File Access
Concurrent access to files with both readers and writers

QServer
Global access to queues using template wrapper holding static queue

STL Containers
Demonstrate array, deque, list, map, native array, queue, set, singlelist, stack, string, unordered_map, unordered_set, and vector

Invocations
Demonstrate function, function pointer, functor, and lambda

Tree Traversal
Illustrates how to walk a tree using either recursion or stack processing

CT-Top Top

C++/CLI

C++ bridge
Demonstrates C++ to and from C# interop

C++/CLI code examples
See especially MixedClasses_again Demonstrates interactions between native C++ and C++/CLI

Syntax examples
Demonstrates C++/CLI arrays, delegates, indexers, properties, types, and disposing

WPF interop
Similar to C++ bridge but uses WPF client.

CT-Top Top

C#

Concurrent File Access
Demonstrates concurrent file access with both readers and writers

Conversions
Demonstrate converting between primitive and string representations using Parse and ToString

CSGraph<V,E,> - Directed Graph
Generic C# Graph library parameterized on Vertex and Edge contents

C# Examples
Demonstrates arrays, indexers, properties, types, and disposing

C# EQuvalence
Demonstrates equivalence operators and virtual functions

Delegate demos
Illustrates classic use of C# delegates

New Delegate syntaxes
Illustrates several short hand syntaxes and use of anonymous delegates and lambdas

Dynamic Types
Demonstrates dynamic types

DLLs
Illustrates use of dynamic link libraries with both implicit and explicit loading

Extension Methods
Demonstrate creation and use of extension methods

High resolution timer interop
Illustrates using native C++ high resolution timer from C#

Lambda Capture
Illustrates how lambda capture works

LINQ Examples
Demonstrate basic LINQ

Examples of LINQ Queries
Demonstrate LINQ queries

LINQ to SQL
Illustrate how LINQ to SQL works by creating, querying, and deleting an SQL database

Method parameters
Demonstrate passing value type by value and reference and passing reference type by value and reference

Recursive Directory walk with delegates
Illustrate how to make a recursive directory tree walker reusable using delegates

.Net Containers
Demonstrate ArrayList, Generic Dictionary, Generic HashSet, Generic List, Hash Table, Generic LinkedList, Generic Queue, SortedList, and Generic Stack

Process Management
Illustrate use of Process class

.Net Reflection
Illustrate use of Type class and Object.GetType()

Serialization
Demonstrate serialization to and from a MemoryStream using SOAP formatting

Testing and Coercing Types
Illustrate testing types and coercing type conversions

Speech to Text
Demonstrate the Speech API reading text

Threads and Tasks
Illustrate using .Net Threads and Tasks

XDocument
Illustrate creation of XML using the XDocument class

CT-Top Top

Sockets and WCF

Sockets
Classes supporting Berkely interface for Windows sockets: Socket, SocketListener, SocketConnecter, SocketSystem. Now Windows only but will be ported to Linux eventually.

Message-Passing communication using older version of Sockets
Will eventually be updated to use the new sockets

TcpClient and TcpListener
Illustrate .Net TcpClient and TcpListener classes

CT-Top Top

WCF Examples

BasicHttp Services
Both declarative and programmatic BasicHttp services - hand crafted

WsHttp Serviceds
Both declarative and programmatic WsHttp services - hand crafted

Self hosted file service
File service using chunked file reads and writes with a WCF service

IIS hosted file service
File service using chunked file reads and writes with a WCF service

Self hosted strings service
Illustrates remote pass by value and reference

File streaming - self hosted
Demonstrates using FileStreams as arguments in service methods

File streaming - IIS hosted
Demonstrates using FileStreams as arguments in service methods

Message-passing WCF communication
Passes messages using BasicHttp, WsHttp, and NetTcp bindings

WCF Peer-to-Peer communication
WCF peers communicate using WCF and display setup and results with WPF

CT-Top Top

Threads and Synchronization

Application Domain
Demonstrates how to create and use an AppDomain instance.

Basic .Net threads
Demonstrate .Net threads

C# Blocking Queue
Uses .Net Monitor for locking and notification

Queued Messages
Illustrates communication between threads using enqueued messages

Queued Messages
Illustrates using asynchronous calls with Synchronized Methods

Starting Threads
Illustrates several different syntax constructions for starting .Net threads

.Net Tasks
Demonstrates use of .Net Tasks which spawn thread pool threads for asynchronous processing

.Net Tasks with Continuations
Illustrates how Task continuations work, e.g., call backs when thread complete's its work

Win32 Thread class
Shows how to build a C++ thread class locks classes based on the Win32 API (you should prefer the C++11 constructs)

Wait for .Net event
Shows how to wait for an event using .Net monitor

Windows Services
Shows how to create and use a Windows Service - developed by Supreeth Murthy

CT-Top Top

Windows and WPF GUI Programming

Basic Windows
Illustrates Win32 GUI Windows programming

Win32 Controls
Illustrates Win32 GUI Windows programming using Controls

C++/CLI Winform
Illustrates how to create winforms with C++/CLI

C# Winform
Illustrates how to create winforms with C#

C# Form with Browse Control
Demonstrates use of FolderBrowserDialog

Synchronous FormInvoke
Demonstrates use of synchronous FormInvoke to return results to UI thread from child thread

Asynchronous FormInvoke
Demonstrates use of asynchronous FormInvoke to return results to UI thread from child thread

CT-Top Top

WPF Examples:

Panel demos
Demonstrate Grid, CanvasPanel, DockPanel, StackPanel, WrapPanel

RoutedEvents
Illustrate how RoutedEvents work

AttachedProperties
Illustrate how AttachedProperties work

WPF controls demos
Demonstrate Tab, FlowDocument, Slider, ProgressBar, Image, Buttons and Labels work

DataTemplate demo
Demonstrate DataTemplate to add formatting functionality to a ListBox control

Change notification
Demonstrate UIElement change notification

ControlTemplate demo
Demonstrate use of ControlTemplate

Dispatcher demo
Demonstrate using Dispatcher to return results to UI thread from child thread

Hooking Messages
Illustrate how to trap Win32 Windows messages

Top

CSE681 - Software Modeling and Analysis

The focus of this course is software architecture on the .Net platform. These code examples, with a few exceptions, illustrate how to use C# code.

Basic Syntax, File Handling, Data Structures, Delegates, Code Structures, .Net Framework, XML Demos, Threads, WinForms, WPF Sockets & Remoting, Web Services, Code Analysis Tools, Managed C++, Prototypes,

SMA Top Top

Basic Syntax:

HelloWorld
A very basic C# console application.

ProgramStructure
Illustrates how to lay out a C# program using an executive and server module. Also shows correct format for manual and maintenance pages.

commandLine
Shows how to read command line, extract file patterns, and find matching files.

C# Examples
Demonstrates arrays, indexers, properties, types, and disposing

C# Equivalence
Demonstrates equivalence operators and virtual functions

Conversions
Demonstrate converting between primitive and string representations using Parse and ToString

Dynamic Types
Demonstrates dynamic types

Extension Methods
Demonstrate creation and use of extension methods

Method parameters
Demonstrate passing value type by value and reference and passing reference type by value and reference

Testing and Coercing Types
Illustrate testing types and coercing type conversions

SMA Top Top

File Handling

demoFiles
Demonstrates the use of Directory, Path, and StreamReader classes to find, open, and read file text.

Navigate
Demonstrates how to navigate a directory subtree using Directory and Path classes.

NavigateWithDelegates
Demonstrates Use delegates to make Navigate reusable.

ConcurrentFileAccess
Demonstrates how to allow multiple processes concurrent access to the same file for both reading and writing.

Base64Encoding
Demonstrates a relatively efficient way of converting binary file data into strings to send as XML messages.

SMA Top Top

Data Structures

.Net Containers
ArrayList, Generic Dictionary, Generic Hashset, Generic List, Hashtable, Generic LinkedList, Generic Queue, SortedList, Generic Stack

LINQ Examples
Demonstrate basic LINQ

Examples of LINQ Queries
Demonstrate LINQ queries

LINQ to SQL
Illustrate how LINQ to SQL works by creating, querying, and deleting an SQL database

CSGraph<V,E,> - Directed Graph
Generic C# Graph library parameterized on Vertex and Edge contents

SMA Top Top

Delegates

Delegate demos
Illustrates classic use of C# delegates

New Delegate syntaxes
Illustrates several short hand syntaxes and use of anonymous delegates and lambdas

Recursive Directory walk with delegates
Illustrate how to make a recursive directory tree walker reusable using delegates

Lambda Capture
Illustrates how lambda capture works

SMA Top Top

Code Structures

Interface-based Programming
Demonstrates composition of program with executive and components that expose interfaces. One component uses three others with references to their interfaces.

Plugin Architecture
Executive loads dlls from a known path, uses reflection to find classes supporting the IPlugIn interface, creates instances of those classes and calls their "test" method.

DLLs
Illustrates use of dynamic link libraries with both implicit and explicit loading

reusableDemo
Shows how to build reusable components using the Abstract Factory Pattern and abstract base classes.

SMA Top Top

.Net Framework

Serialize
Shows how to serialize an object's state to a stream.

AttributedProgram
Illustrates creation and use of custom attributes in C# programs.

Hi Resolution Timer using Platfrom Invoke
Demonstrates how to use Platform Invoke to access performance counters to build a high resolution timer (microsecond resolution - 10,000 times finer resolution than standard FCL timers).

RandomEvents
Creates random numbers and random events, including events occurring with some average density over time.

.Net Reflection
Illustrate use of Type class and Object.GetType(). Demonstrates how to use Directory operations and Reflection to extract type information.

AppDomain Demo
Demonstrates how to create a child AppDomain, load an assembly into the child, find types defined by the assembly, instantiate them, and call member functions on the instance.

SMA Top Top

XML Demos

xmlApps
Demonstrates how to use the XmlDocument, XmlNodeReader, XmlTextReader, and XmlTextWriter classes.

XMLdemo
Illustrates how to programmatically added, delete, and modify elements of an XML file using the XMLDocument and XMLNode classes.

XMLMessages
Shows how to build and parse a message structure that could be used in a remoting communication layer. No actual remoting is done in this demo.

Base64Encoding
Good way to encode binary data as a string of characters, perhaps to store in XML. With Base64 Encoding you get a smaller expansion than Hexadecimal (base16) encoding.

SMA Top Top

Threads and Synchronization

Basic .Net threads
Demonstrate .Net threads

Starting Threads
Illustrates several different syntax constructions for starting .Net threads

Wait for .Net event
Shows how to wait for an event using .Net monitor

C# Blocking Queue
Uses .Net Monitor for locking and notification

Queued Messages
Illustrates communication between threads using enqueued messages

Queued Messages with Synchronized Methods
Illustrates using asynchronous calls with Synchronized Methods

.Net Tasks
Demonstrates use of .Net Tasks which spawn thread pool threads for asynchronous processing

.Net Tasks with Continuations
Illustrates how Task continuations work, e.g., call backs when thread complete's its work

Threads and Tasks
Illustrate use of .Net Threads and Tasks

Process Management
Illustrate use of Process class

Concurrent File Access
Demonstrates concurrent file access with both readers and writers

AsyncExamples
Shows how to make asynchronous calls to both local and remote objects.

Thread Pool Demo
Illustrates how to run a method on a thread pool thread and receive a callback when the method completes.

BackgroundWorker Thread
Illustrates use of worker thread and Form.Invoke in a WinForm application.

synch
Shows how to serialize access to shared resources using Win32 threads and synchronizing constructs.

WorkerThread
One more demonstration of threading under .Net.

ProcessDemoWin32
Shows how to programmatically start a process using the Win32 API.

SMA Top Top

Windows, Forms, and Contols

WinMin
Builds a very simple windows application using the Win32 API with a message loop and WinProc function.

WinForm Demo
shows how to use images and react to mouse moves in a WinForm application.

dialogDemoCS
Shows how using a worker thread in C# can prevent UI from freezing during intensive computations.

dialogDemoWin32
Shows how using a worker thread in MFC can prevent UI from freezing during intensive computations. Also demonstrates the use of user defined Windows messages (Win32).

usingListView
Demonstrates use of ListView control and display or hiding of forms at run-time.

DirMgr
Shows how to populate a TreeView with directory and file information, using lazy evaluation. Also shows how to expand the TreeView to the current directory when program starts.

FileDialogDemo
Illustrates use of FileDialog control in a WinForm application.

FormInvokeDemo
Shows how to use FormInvoke to allow a worker thread to safely communicate with a UI in C#.

nonClientHit
Illustrates interacting with the underlying windows message loop to react to NChits - messages due to user actions in the Non-Client area (not available from the exposed WinForm events).

demoControls
Demonstrates how to build both list and treeview controls that add functionality to those provided in the Winform toolkit. The TreeViewPlus control, for example, derives from TreeView and adds automatic lazy initialization of the control with drives, folders, and files. It opens the control expanded to the current directory.

SMA Top Top

WPF Demos

WPF Panel demos
Demonstrate Grid, CanvasPanel, DockPanel, StackPanel, WrapPanel

WPF RoutedEvents
Illustrate how RoutedEvents work

WPF AttachedProperties
Illustrate how AttachedProperties work

WPF controls demos
Demonstrate Tab, FlowDocument, Slider, ProgressBar, Image, Buttons and Labels work

WPF DataTemplate demo
Demonstrate DataTemplate to add formatting functionality to a ListBox control

WPF Change notification
Demonstrate UIElement change notification

WPF ControlTemplate demo
Demonstrate use of ControlTemplate

WPF Dispatcher demo
Demonstrate using Dispatcher to return results to UI thread from child thread

WPF Hooking Messages
Illustrate how to trap Win32 Windows messages

SMA Top Top

Sockets and Remoting

socketDemo_DotNet
Illustrates how to build a socket-based communication program in .Net. Seperate projects build single-threaded and multi-threaded servers.

socketDemo_Win32
Illustrates how to build a socket-based communication program using Win32 API. Seperate projects build single-threaded and multi-threaded servers.

Message Framing
Shows how to extract XML messages from a socket transmission (sockets only understand bytes).

Message Framing with threads and queues
Shows how to extract XML messages from a socket transmission in a robust, reusable way with the help of child threads and blocking queues.

TCPClientServer
Sets up socket communication under .Net using the wrapper classes TCPClient and TCPServer.

RemotingDemo
Demonstrates communication between two machines using .Net remoting and singleton server.

Remoting_BilateralComm
Shows how to set up both a client channel and a server channel that support acting as both a client and a server in the same process. The trick is to use named channels.

Remoting_PassByRef
Illustrates how remoting server can communicate back to client using a Pass-by-Reference object.

Remoting_PassByRefFileXfer
Shows how to download files from a single-call server using Pass-by-Reference object.

Remoting_PassByValue
Illustrates how to pass an object of a user-defined type to a remote object by value.

PeerToPeerPrototype
Shows how to build a chat application using bilateral remoting with named channels.

BijlaniPrototype
A student prototype, with presentation, that compares performance of the three remoting activation models in an XML message-passing context.

SMA Top Top

Web Services and a little bit of ASP

CalcWebService
Presents a minimal web service.

demoWebService
Demonstrates how to build a basic web service using C# code-behind. Includes step-by-step screenshots

FileXferWebService
Shows how to transfer files to a remote location using text messages.

demoAspApplication
A simple Active Server Pages demo. Requires the creation of a virtual directory. Instructions are included.

SMA Top Top

Code Analysis Tools

Tokenizer
Toker extracts words from files. This is useful for analysis of source code files.

grammar
Demonstrates use of toker, Semi-Expression analyzer, and Grammar parser to perform simple analysis on source code.

SMA Top Top

Managed and Unmanaged C++

Introduction to Managed C++ Demo
Managed C++ class that provides basic file handling and viewing.

Managed C++ Examples
Demonstration of managed classes, Mixed managed and unmanaged classes, managed exceptions, unmanaged classes holding references to managed code, marshaling of data between managed and unmanaged code, and use of Platfrom Invoke access to the Win32 API from managed C++.

Unmanaged C++ from C#
Shows how to call a C++ module from a C# application. Uses a C++ tokenizer from a C# console application.

SMA Top Top

Software Repository Prototypes

Scanner
This is a prototype of a program to scan through a collection of files that are linked by references in manifest files. It was a small prototype for a Software Repository project.

Test Harness Prototype
Demonstrates how to build a test harness that loads test libraries into a child AppDomain so they can be unloaded after testing. The test harness loads the library assemblies, uses reflection to find test classes that support the ITest interface, creates instances of the discovered classes and invokes their test() method, using InvokeMember.

Run Compiler
Shows how to create a build process by spawning the C# compiler in a child process.

Top

CSE686 - Internet Programming

The main concerns of this course are models for both client and server side web programming. Many of the examples use the Asp.Net MVC framework.

Client Side Programming, Server Side Programming Client-Server Programming

IP Top Top

Client-side Programming


DropDown Menu
Illustrate how to build a drop-down menu with jQuery (Javascript library) and CSS.

Javascript Examples
This is a demo of Javascript basics written for IE6. Since IE is now more standards compliant some of the formatting is no longer correct.

jQuery Demos
Illustrates basic operations with jQuery Javascript library:

  • Creating alerts
  • Responding to button clicks on page elements
  • Adding new page elements
  • Dynamically changing styling with button clicks and mouseovers
  • Animating page elements by changing styles
  • hiding page elements

IP Top Top

Server-side Programming


Asp.Net Examples

  • Default.aspx illustrates creation of a simple view using controls.
  • Partition.aspx example illustrates partitioning web page processing into:
    • A library of functions called by C# code in page script blocks
    • An Asp control used for navigation
    • Page markup for rendering the view
  • Class.aspx example illustrates use of reflection to discover application types.

More Asp.Net Examples

  • Downloading file
  • Uploading file
  • Data Binding
  • XML processing

Calc
Simple calculator compares processing on client, on server with ASP, and on server with Asp.Net.

Asp.Net Life Cycle
Demonstrates many of the events that fire when a composite page loads.

Load Control
Illustrates how to create a custom control and load/unload dynamically.

Create database using LINQ
This is a console application that shows how to create a database, add tables, make queries, and delete using LINQ.

MvcState
Demonstrates an Asp.Net Mvc application using Session to store a shopping cart.

MvcFileMgr
Demonstrates implementing File Transfers in an Asp.Net Mvc application.

MvcCRUDwithXML
Illustrates building Asp.Net Mvc site using XML as the backing store.

MvcCRUDwithSQL
Illustrates building Asp.Net Mvc site using SQL Server as the backing store.

Books Site
Illustrates developing sites with many-to-many relationships using Asp.Net Mvc.

IP Top Top

Client-Server Programming


Classic HTML
Classic HTML application uses Markup for content, CSS for presentation, and Javascript for behaviour.

HTML5 and Javascript
Illustrates some layout techniques using HTML5.

Ajax Introduction
Simple demonstration of Ajax interaction with server. It appears to have broken with the last Asp.Net Mvc version change. I will fix eventually. In the meantime you can create a new Asp.Net Mvc application and reproduce the code here to get this working.

IP Top Top

CSE687 - Object Oriented Design

This project-based course focuses on tactics of design using Standard C++ and the Standard C++ library. The newest examples use features of the C++11 standard.

Basic Syntax, File Handling, Abstr Data Types, STL, Other Libraries, Data Structures, Code Structures, Callable Objects, Sockets & Remoting, Threads & Synchronization, Prototypes, Code Analysis Tools, C++/CLI, GUIs, Small Demos

All of the code in these folders has been written in C++ using Visual Studio. I have had very good luck letting the Project Wizard convert older projects to current Visual Studio projects. Usually if a failure occurs it is because the Visual C++ compiler is now more standard conforming. When these failures occur the error messages are usually quite good and you should have no difficulty making the few changes (most of this has already been done for you, but not in every single folder).

OOD Top Top

Basic C++ Syntax and Semantics

BASIC
Classes and basic class relationships.

Relationships
Demonstrates the four primary class relationships: composition, inheritance, using, and aggregation (weak form of composition).

Equiv
Shows how to call constructors in different program contexts.

Hiding
Demonstrates hiding and other substitution errors in polymorphic designs.

casts
Four new casts: static_cast, reiterpret_cast, const_cast, dynamic_cast.

exceptions
Illustrates use of C++ exceptions and standard exception classes.

Alias Demo
Aliases used in Symbol Table definition

DEMOS
Demonstrations of:

  • callbacks
  • DemComp - illustrates syntax and issues with composition
  • DemInher - illustrates syntax and issues with inheritance
  • file handling
  • templates
  • member function pointers
Current students of CSE687 - OOD will want to look demagg and deminher carefully. They demonstrate how constructors and destructors are called, some circumstances when temporaries are created, and most importantly why you must use initialization sequences for all the constructors you write (with the exception of default constructors).

OOD Top Top

File Handling

FileSystem for Linux
Provides capabilities to extract information from the linux file system, e.g., directories, files, and paths.

FileSystem for Windows
Same capabilities and interfaces as FileSystem-Linux for the Windows operating systems.

iostreams
Demonstrates basic iostream operations, formating, reading and writing with files, and use of stringstreams.

streambufs
Demonstrates a few uses for the streambuf classes buried inside iostreams, fstreams, and stringstreams.

streambuf example
Shows how to redirect a stream.

Concurrent File Access
Concurrent access to files with both readers and writers

OOD Top Top

Abstract Data Types

STR
A simple string class used to illustrate Abstract Data Types - that is, orchestrating your C++ design and implementation to support almost all of the operations provided for built in types.

Math::Vector
A fixed size ordered collection of coordinates. Coming soon - Math::Matrix (linear operator on Vectors)
These will be used with graph visualizer, currently in the early stages of design.

OOD Top Top

STL

STL Containers
Demonstrate array, deque, list, map, native array, queue, set, singlelist, stack, string, unordered_map, unordered_set, and vector

STL
Illustrates basic use of the STL containers, iterators, and algorithms.

STL_helpers
More STL related code that will be used to look at parts of the STL.

STL Odds and Ends
Illustrates use of inserters and functors for selecting sort method in associative containers.

functors
Demonstrates common uses of functors - function objects.

OOD Top Top

Other Library Demos

spawnProc
Shows how to run a program from inside another, by creating its process and passing command line arguments.

Chrono Timer
Definition of high resolution timer using the std::chrono library

OOD Top Top

Data Structures

Graph<V,E> - Directed Graph library
Implements a directed graph data structure. The class is templatized on vertex and edge contents.

MTree
Implements an M-ary Tree data structure, e.g., unbalanced tree where any vertex may have an arbitrary finite number of children.

Tree Traversal
Illustrates how to walk a tree using either recursion or stack processing

HashTable
Good example of templates, policy - HashString, and traits - key_type, value_type, iterator. Shows how to implement container and iterator classes so they integrate with the STL algorithms.

Blocking queue
Threadsafe blocking queue using std::queue, std::condition_variable and std::mutex

QServer
Global access to queues using template wrapper holding static queue

Xml Document
Provides an XML Document class that supports reading XML from files or strings, programmatically building and editing XML documents and display of the resulting documents.

Math::Vector
A fixed size ordered collection of coordinates. Coming soon - Math::Matrix (linear operator on Vectors)
These will be used with graph visualizer, currently in the early stages of design.

OOD Top Top

Code Structures

Classic Interface with Object Factory
Demonstrates use of interface and object factory to create instance of a polymorphic object.

Objects that support multiple interfaces and use object factory
This is a technique for supporting extension of interfaces without breaking a lot of client code. This is essentially what COM does.

Factory with static map
Illustrates the use of a class factory to support the program-to-interface paradigm. Factory uses a static map of creational function pointers.

Interfaces with static factory function
Illustrates how to build object factories using static factory method. Creates any object found on a give inheritance hierarchy.

XmlDocument uses abstract base class
Illustrates using abstract base to support sharing code and data between derived classes. Uses global factory methods.

MakeDLL
Shows how to build a DLL. See the accompanying presentation about the required project properties.

DLL Demo
Demonstrates how to create and load, either implicitly or explicitly, dynamic link libraries (DLLs).

Notifier
Illustrates use of events and callbacks in a "Publish/Subscribe" structure.

SmartPointer
Illustrates how to build a "smart pointer" class - prefer std::unique_ptr.

SmartPtr
Illustrates how to build a reference counted "smart pointer" class - prefer std::shared_ptr.

Traceable
Illustrates use of inheritance to extend, without modification, an existing class - here the std::string class.

OOD Top Top

Callable Objects

Callable Objects
Demonstrates functions, function pointers, functors, and lambdas

functors
Demonstrates common uses of functors - function objects.

OOD Top Top

Sockets

Sockets
Provides classes Socket, SocketListener, SocketConnecter, and SocketSystem. This is a new design that supports both IP4 and IP6 on Windows. Will port to Linux eventually.

socketDemo_Win32
Illustrates how to build a socket-based communication program using Win32 API. Seperate projects build single-threaded and multi-threaded servers. Uses older version of sockets package.

Message-Passing communication using older version of Sockets
Will eventually be updated to use the new sockets

OOD Top Top

Threads and Synchronization

C++ Threads and Locks
Demonstration of C++11 threads and locks, futures, and tasks

Blocking queue
Threadsafe blocking queue using std::queue, std::condition_variable and std::mutex

Win32 Thread class
Shows how to build a C++ thread class and locks classes based on the Win32 API (you should prefer the C++11 constructs)

Concurrent File Access
Concurrent access to files with both readers and writers

synch
Shows how to serialize access to shared resources using Win32 threads and synchronizing constructs.

ProcessDemoWin32
Shows how to programmatically start a process using the Win32 API.

OOD Top Top

Code Prototypes

Project1HelpS14
Provided helper code for first project (searching multiple files for text). Also includes completed instructor's solution.

Project2HelpS14
Provided helper code for second project (builds XML Document Model). Also includes nearly complete instructor's solution: XmlDocument.

Project3HelpS14
Provided helper code for third project. Includes a nearly complete Set of sockets classes.

Project4HelpS14
Provided helper code for fourth project. Includes demonstration of building a WPF GUI using C++/CLI. This uses all code as C++/CLI does not have a Xaml compiler.

OOD Top Top

Code Analysis Tools

C++ code parser
Parser is a container for Rules and Rules are containers for actions. Each rule is a detector of some grammatical construct. When a rule matches a token sequence (called a semi-expression) it invokes its actions.

OOD Top Top

C++/CLI

C++ bridge
Demonstrates C++ to and from C# interop

C++/CLI code examples
See especially MixedClasses_again Demonstrates interactions between native C++ and C++/CLI

Syntax examples
Demonstrates C++/CLI arrays, delegates, indexers, properties, types, and disposing

WPF interop
Similar to C++ bridge but uses WPF client.

ManagedCPP
Illustrates how to use managed extensions for C++ and how to mix managed and unmanaged code.

Project Helper - WPF using C++/CLI
Demonstrates how to build a WPF GUI using C++/CLI. This uses all code since C++/CLI does not have a Xaml compiler.

OOD Top Top

GUIs

WinMin
Builds a very simple windows application using the Win32 API with a message loop and WinProc function.

Basic Windows
Illustrates Win32 GUI Windows programming

Win32 Controls
Illustrates Win32 GUI Windows programming using Controls

C++/CLI Winform
Illustrates how to create winforms with C++/CLI

C++/CLI WPF app
Provided helper code for fourth project. Includes demonstration of building a WPF GUI using C++/CLI. This uses all code as C++/CLI does not have a Xaml compiler.

OOD Top Top

Other Small Demos

Windows Services
Shows how to create and use a Windows Service - developed by Supreeth Murthy

Efficiency
Provides a series of demonstration programs illustrating performance issues due to: algorithms, data structures, copying, memory allocation, etc.

fixExtensions
Shows how to open any file matching a specific pattern, and make text changes. This is a prototype for a tool I use to manage website files.

HexConvert
Helper macros used to convert binary code to and from hexadecimal strings.

OOD Top Top

CSE775 - Distributed Objects

Distributed Objects focuses on programs that are distributed across process, machine, and technology boundaries.

The first part of the course is concerned with COM, the Microsoft Component Object Model technology. That technology is pervasive throughout windows and its applications, e.g., Windows shell, IE, IIS, Office, and the .Net CLR.

The remainder of this course explores interesting new frameworks and programming models through student projects.

Basic Comp Tech, C++ COM Comp, ATL-based COM Comp, COM Tech, ActiveX Comp, Interop, C# Tech, C# Comp, Windows Prog

Attributions:

Several projects in the folders below are modifications, some minor, some with significant changes, of code provided with the book:

Inside Distributed COM, Guy Eddon and Henry Eddon, Microsoft Press, 1998.
We used this excellent book for two years in this course. It is loaded with example code, thoughtfully constructed, and most simple in structure, with concise but effective documentation for builds.

One ActiveX project, ATLPanel, was adapted, with only minor modifications, from code provided with the book:

ActiveX Template Library Development with Visual C++ 6.0, Nathan Wallace, Wordware Publishing, 1999.

Building These Projects:

Building COM projects is a little more complicated than building console or straight Windows applications. Here are some guidelines:
  1. Find all the idl files in the project (most have one, some have two or more), right click on them and select compile. This invokes the MIDL compiler to generate header and implementation files needed for the C++ compiles.
  2. Right-click on each COM component project and select rebuild. This includes any proxy projects that are part of the solution. Building ProxyStub code prior to Vista required linking to rpcndr.lib. This is no longer shipped with Vista, and is not required as one of the other lib files now supplies that functionality. Just remove rpcndr.lib from the linker input properties, and rebuild.
  3. Go to the project directory and dir /s *.dll (for In-Proc components) and dir /s *.exe (for Out-of-Proc components). Register each In-Proc component with regsvr32 xxx.dll. Register each Out-of-Proc component by running the EXE with the switch /RegServer. You will find a screen shot here that shows how to add regsvr32 to the Visual Studio Tools Menu to do that more easily. To do any registrations within Visual Studio under Vista, you need to run Visual Studio with "run as administrator" option.
  4. If the client and component do not share the same context (threading model and security attributes) then you will need to insure that the ProxyStub code is compiled to build the ProxyStub dll, and then register the dll, as above. In some of the workspaces that need ProxyStubs I have provided projects to build them. My recommendation is to build the project without worrying too much about this, but if you get a failure in CoCreateInstance, then look for a ProxyStub that needs building or registering.
  5. Now you can set the client(s) as startup project(s) and compile and run them.
DO Top Top

Basic Component Technology

progToInterface
Code from the CSE687 course that has some relevance to this course.

Interfaces
This is an example of programming to an interface and using a factory function in standard C++ code.

DemoDll
This demonstrates the advantages of programming to interfaces and using factory functions. The dllClient runs smoothly with DemoDll, but crashes when run with RevisedDemoDll because it makes references to implementation details in the original DemoDll. The interfaceClient runs smoothly with either InterfaceDll or RevisedInterfaceDll because it uses an interface and factory function to communicate with the dll.

DO Top Top

COM components in C++ - no ATL or MFC support

INPROC3
In-Proc component that adds two integers.

inproc_Ex1
In-Proc component that accepts a string from the client, and sends another string back. The interface uses BSTRs.

OUTPROC1
Illustrates how to build an Out-of-Proc component that supports the Multi-Threaded model, allowing multiple client threads to access the server functions concurrently. The main server thread waits on an event to allow clients to access the component's interface. When the final release is called the event is triggered and the server shuts down. Shared component resources are locked using a critical section.

OUTPROC3b
Demonstrates how to build an Apartment-Threaded server. To support this model, all calls are serviced by single server thread, extracting request messages from a Windows message loop. This project uses TypeLibrary marshaling, achieved by using an oleautomation attribute in its IDL.

INTERFAC
Out-of-Proc component that implements five interfaces illustrating how to send back and forth basic types, wchar_t strings, BSTRs, pointers, structs, and arrays. The workspace demonstrates how to declare the interfaces in IDL and how to handle these types on both the component and client sides.

DO Top Top

ATL-based COM Components

ATLdemo
Inproc component built with ATL.

ATLexe
Demonstration of an Out-of-Proc component, built with ATL.

ATLPanel
ActiveX control: paints its interface and uses ConnectionPoints-based events.

ATLStrings
Simple component accepts a string and returns another. Three clients are provided. One written in straight C++, on using CComPtr smartpointers (provided by ATL), and one using com_ptr_t smartpointers (provided by Visual Studio).

ATLWinExp
Builds Frame window and a Dialog, using ATL windows classes.

ATLDemo7
Demonstrates building an In-Proc component with ATL 7.0. - not too much changed from 6.0 if you don't use attributes.

ComponentCallsComponent
Shows how to build a component that is a client of another (inner) component. Also uses CComQIPtr and CComBSTR classes to simplify the implementation of a client.

dirControl
This project builds an In-Proc COM component that makes a directory listing of the current directory. The project shows how to use the control from a client that uses Visual Studio COM support classes, and also how to use the control on a web page.

DO Top Top

COM Technologies

Connection Points
Out-of-Proc component communicates with client through Connection Points.

TestConnPts2
Shows how to build an ActiveX control that declares a connection point interface.

Dispatch
Demonstrates how to build a COM component that exposes an IDispatch interface (the easy part) and how to call a IDispatch interface from C++ code (the not so easy part).

REGISTRY
Demonstrates how to read and write to the registry. This code is based on code from the book Win32 System Services, Marshal Brain and Ron Reeves, Prentice-Hall, 2001. I've made minor modifications to the code, but the ideas and structure are theirs.

types
Shows how to convert to and from Unicode strings.

DO Top Top

ActiveX Controls

AxDemo
Shows how to build ActiveX controls and support a control's events using connection points.

WebBrowser
Demonstrates how to build your own browser application.

Browser Events
Web browser control hosted in C# WinForm. Exposes mouse events to Form.

DO Top Top

.Net, COM, and unmanaged C++ Interoperation

Interop with COM
Shows how to use a COM component (inproc_Ex1) from a C# client.

Bridge from C++ to C#
Illustrates use of a managed C++ class to wrap legacy C++ code (Tok module) so that a C# class can use it.

C# and COM Interoperation with events
Uses Connection Points to do a remote callback from COM component to C# client.

DO Top Top

C# Techniques

DelegateDemos
This demonstrates the use of delegates, delegates with events, and delegates in multi-threaded programs.

AsynchCallback
Demonstrates how to use asynchronous callbacks with delegates.

C# and COM Interoperation
Uses Connection Points to do a remote callback.

Navigate
Illustrates how to navigate a directory tree using .Net classes.

Navigate with Delegates
Illustrates how to make the navigate code reusable through delegates.

DO Top Top

C# Components

Components
Demonstrates the building of .Net libraries, components - things that can live in the component designer, and controls - things that can live in the forms designer.

DO Top Top

A Little Windows Programming

basicWindows
MFC based Frame window.

moreBasicWindows
Illustrates how to write a Windows Application in straight C++ and with MFC. Also shows how to create a console in a Windows Application and how to create a Window in a console application.

DlgRecipe
This project builds a simple Dialog application, using MFC, and provides a series of screen shots to show you how to build one like it. The purpose of the project is to allow students who have done virutally no windows programming a way to survive the later projects.

Drawing on Forms
Shows how to draw text and lines on a form.

FWRecipe
This project builds a Frame Window application, using MFC, and provides a series of screen shots to show you how to build one like it. The purpose of the project is to allow students who have done virutally no windows programming a way to survive the later projects.

DO Top Top

CSE776 - Design Patterns

This course provides instructor and student presentations of each of the 23 design patterns from the book "Design Patterns" by Gamma et. al. The code examples, here, are ones I use in my presentations for this class. Typically a presentation will include the simplest shortest code that illustrates how the pattern can be implemented and a slightly longer example showing how it could be used in an application.

Instructor's Presentations:

DP Top Top

Abstract Factory
Pattern for building factories for families of products.

Adapter
Pattern for wrapping a class to become part of an inheritance hierarcy.

Bridge
Pattern that supports independent variation of abstraction and implementation.

Builder
Pattern for building complex composite objects.

Command
Pattern for an application to react to library events (don't call us, we'll call you).

Composite
Pattern for building tree-based composite objects.

Facade
Pattern for wrapping a collection of interacting objects behind a simplfying interface.

Flyweight
Pattern for efficiently creating a large number of objects that share some of their state.

Memento
Pattern that supports backtracking and undo operations.

Strategy
Pattern for implementing, on demand, one of a number of related strategies.

DP Top Top