Sample Code from All Courses

Revised: 23 November 2005
Home  Courses  SWTrack  Code  Handouts  StudCult  CoreTech  Books  Articles  Math  Research  CASE Projects  Project Topics  SWDev  WebDev  News  OtherLinks  SiteDesign  Graduates  AllPages  Office Hours  Seminars  Notices  Contents

CSE681-SWMAA  CSE686-IP  CSE687-OOD  CSE691-CP  CSE775-DO  CSE776-DP  CSE778-AWP  CSE784-SWS

Getting Ready for Code Demo

Code Location in this page:
CSE681-SWMA CSE686-IP CSE687-OOD CSE775-DO CSE776-DP CSE778-AWP CSE784-SWS


" There are two ways of constructing a software design;
one way is to make it so simple that there are obviously no deficiencies,
and the other way is to make it so complicated that there are no obvious deficiencies.
The first method is far more difficult. "
- C.A.R.Hoare


Feedback

I welcome constructive feedback about these code examples. You may see ways to make their messages clearer or know of better approaches - especially if you are a graduate of our program and are developing software everyday. Feel free to comment - I won't be offended, but rather pleased that you were interested enough to contact me: Mail Home

Note:

The college server does not have .Net installed, so these examples will not execute from the server. You will have to download to a .Net enabled machine. Any of the ECS cluster machines will do.

You will find this code in one of these locations:
  1. www.ecs.syr.edu/faculty/fawcett/handouts/CSEXXX/code
    where CSEXXX is one of the following: CSE681, CSE686, CSE687, CSE775, CSE776, CSE778, or CSE784
  2. www.ecs.syr.edu/faculty/fawcett/handouts/CoreTechnologies

Top

Core Technologies

Basic use of C# and Framework Class Librarys

HelloWorld
A very basic C# console application.
helpSession
Shows how to create console and WinForm applications.
ProgramStructure
Illustrates how to lay out a C# program using an executive and server module. Also shows correct format for manual and maintenance pages.
conversions
Illustrates how to convert between numeric types and their string representations.
demoFiles
Demonstrates the use of Directory, Path, and StreamReader classes to find, open, and read file text.
commandLine
Shows how to read command line, extract file patterns, and find matching files.
collections
Demonstrates use of HashTable and SortedList collections. These were prototypes for Project #1, concerned with C# dependency analysis.
Serialize
Demonstrates how to serialize an object of a user-defined type to a memory stream. The same technique can be used to serialize to a file.

Top

CSE681 - Software Modeling and Analysis

Most of these code demonstrations use the C# language. One shows how to interoperate with unmanaged C++.

File Handling

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.

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.

Delegates, Threads, Processes, Asynchronous Calls

delegateDemos
Illustrates use of delegates and events.
NavigateWithDelegates
Shows how to make navigation a reusable component via delegates.
threadDemo
Illustrates use of worker thread and Form.Invoke in a WinForm application.
ThreadProblems
Demonstrates a variety of threading problems, e.g., deadlock, race conditions, starvation, corruption of shared resources.
QueuedMessages
Demonstrates how two threads can communicate through a shared queue.
synch
Shows how to serialize access to shared resources using Win32 threads and synchronizing constructs.
WorkerThread
One more demonstration of threading under .Net.
ProcessDemo
Illustrates how to programmatically start a process in C#.
ProcessDemoWin32
Shows how to programmatically start a process using the Win32 API.
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.
Queued Messages with Synchronized Methods
Shows how to use Synchronized Methods to serialize access to a queue shared by two threads.

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.

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.

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.

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.

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.

Other Interesting Demos

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.
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.
reflection
Demonstrates how to use Directory operations and Reflection to extract type information.
reusableDemo
Shows how to build reusable components using the Abstract Factory Pattern and abstract base classes.

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.

Common Langugage Runtime (CLR) Demos

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.

Top

CSE686 - Internet Programming

The code in this section is devoted to client-side and server-side web programming on Windows platforms under .Net.

Client-side Programming

browser
Shows how to embed the IE browser control in an application and support application handling of mouse events on a web page.
commandLine
Shows how to read command line, extract file patterns, and find matching files.
conversions
Illustrates how to convert between numeric types and their string representations.
delegateDemos
Illustrates use of delegates and events.
demoFiles
Demonstrates the use of Directory, Path, and StreamReader classes to find, open, and read file text.
HelloWorld
A very basic C# console application.
JavaScript
Basic demonstrations of the use of Javascript and cascading style sheets in web pages.
Navigate
Demonstrates how to navigate a directory subtree using Directory and Path classes.
NavigateWithDelegates
Shows how to make navigation a reusable component via delegates.
Scripting
Illustrates how script can access and use the browser's document parse tree.
WebBrowser
Demonstrates how to embed the IE web browser control in an application and use it to render a variety of file types.
WinForm Demo
shows how to use images and react to mouse moves in a WinForm application.
WinMin
Builds a very simple windows application using the Win32 API with a message loop and WinProc function.
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.

Server-side Programming

AspApps
Provides basic examples of ASP and ASP.Net applications.
AccessProjects
Shows how to use the Access database from a program.
ADOConsoleDB
Illustrates basic use of the Active Data Object classes.
ADOxmlDemo
Demonstrates use of ADO to convert XML to and from a set of relational tables.
AspExamples
Contains a set of projects that illustrate: ASPSWproductsDB
Shows how to display Database data on a web page.

Top

CSE687 - Object Oriented Design

All of the code in these folders has been written in C++ using Visual Studio 6.0 or Visual Studio 7.0. Most of the folders have 7.0 projects, many have 6.0 projects as well. I have had very good luck letting the Project Wizard convert 6.0 projects to 7.0 projects. Usually if a failure occurs it is because the Visual C++ compiler is more standard conforming in version 7.0. 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).

Basic C++ Syntax and Semantics

BASIC
Classes and basic class relationships.
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.
Relationships
Demonstrates the four primary class relationships: composition, inheritance, using, and aggregation (weak form of composition).

Miscellaneous Small Demos

DEMOS
Demonstrations of: callbacks, aggregation and inheritance details, file handling, member function pointers, templates. 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).
help2004
Workspace used for Visual Studio help session, Friday, Jan 24th, 2004.
Shows how to use fileInfo module to expand wildcards, and how to build multi-module project.
Help2003
A workspace used during the Visual Studio help session held Friday, Jan. 23rd, 2003.
HexConvert
Helper macros used to covert binary code to and from hexadecimal strings.
Pr1HelpSp04
Provides CppToker and CppSemiExp Module prototypes for use with code analysis required in Project #1.
Pr1HelpSp03
Shows how to use simple string operations to create XML or HTML tags.

Encapsulating Abstract Data Types and Other Useful Classes

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.
fileInfo
Reusable module supporting file and directory operations, including finding all files and their attributes.
getFiles
Shows how to use the fileInfo object (see above) to do all the file and directory handling for Project #1.
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.
CppSemiExp
CppSemiExp module uses CppToker module to scan and help parse C++ code files. CppSemiExp provides a plug-in architecture that supports inserting filters into the analysis stream. This will be useful for Project #1, Spring 2004.
semi
Semi is a reusable "Semi-Expression evaluator that uses another reusable module Tok, a tokenizer that can be parameterized for tokenizing either C/C++/C# code or HTML/XML. This will be useful for Project #2, Spring 2003.
smartPointer
Illustrates how to build a "smart pointer" class.
smartPtr
Illustrates how to build a reference counted "smart pointer" class.
thread
Shows how to build a thread class that works a lot like the C# Thread class. Synchronization is also illustrated.
traceable
Illustrates use of inheritance to extend, without modification, an existing, reusable class - here the std::string class.
vector3D
Develops an Abstract Data Type based on mathematical 3 dimensional vector. Provides all of the operations expected in a linear vector space. Illustrates nicely how to design operators for a mathematical object.
XML
A module that supports the reading and writing of XML data. It is not DOM based, nor is it event-based like the SAX processors. It is simply a procedural reader/writer facility.

Larger Project-Style Demos

CATALOG
Catalog program demonstrates use of modules, polymorphic decoupling, directory navigation, file pattern matching.
Dups
Program to find duplicate files in a directory tree. Uses STL containers to efficiently store file and path names. Provides a reusable directory navigation component.
Pr2Help
Demonstrates organization of a program to process C++ code.
Pr2PartialSoltution
A toolkit prototype for type analysis.

Demonstrating OOD Principles

factories
Illustrates how to build object factories. Creates any object found on a give inheritance hierarchy.
Interfaces
Illustrates the use of abstract base classes as interfaces and the use of factory functions. These are intended to break compile-time dependencies caused by the client including implementation detail from header files.
notifier
Illustrates use of events and callbacks in a "Publish/Subscribe" structure.
progToInterface
Illustrates the use of a class factory to support the program-to-interface paradigm.

IOStreams Examples

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.

STL Related Examples

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.

Other Interesting Code Samples

Efficiency
Provides a series of demonstration programs illustrating performance issues due to: algorithms, data structures, copying, memory allocation, etc.
MakeDLL
Shows how to build a DLL. See the accompanying presentation about the required project properties.
ManagedCPP
Illustrates how to use managed extensions for C++ and how to mix managed and unmanaged code.
Building DLLs - setup.doc
Shows project settings and steps for building a C++ DLL.
spawnProc
Shows how to run a program from inside another, by creating its process and passing command line arguments.
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.

Top

CSE775 - Distributed Objects

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, very 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.
  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.
  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.
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.

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.

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.

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.

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.

.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.

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.

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.

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.

Top

CSE776 - Design Patterns

Top

CSE778 - Advanced Windows Programming

Top

CSE784 - Software Studio


This Page is Under Construction!

Top