Source Samples and Utilities


Samples
DirectX 9 Samples Binary DirectX 9 samples and demos.
SVG Viewer Displays SVG files using GDI+. 
Windows Shell Library and Samples View the  description of Windows Shell Library and Samples.
Single Instance Demonstrates how to create a single running instance of an application. If a previous instance exists, that window is brought to the foreground and restored if necessary, then the application exits. Otherwise, a mutex is created by the process to ensure that no other instance is created during the lifetime of the application window.

When the application is closed the mutex is closed as well so that new instances can be created. Note that if the application exits unexpectedly Windows releases the process resources, including the mutex, automatically. 

SysInfo This sample is a dialog-based application that displays system information (hardware and Windows). It demonstrates the following:
  • Creating a dialog with the GUI Builder 
  • Working with resources 
  • Creating a project and generating an executable 
  • Using external resource scripts 
  • Integrating Resource Compilation

The sample comes with step-by-step instructions on how to implement a complete dialog-based application that uses resources and a custom icon.


Additional Samples
Object Serialization Example

Method Consistency Check

 

Object Serialization

In Smalltalk MT, the standard serialization methods use memory-mapping technology. MappedObjectStream implements an easy-to use interface. An instance of MappedObjectStream maps a set of objects into the address space of the process. The top-level object is called the root object. There is only one root object, but it can be arbitrary, and in particular it can be a collection.

1. To serialize an object:

| bytes newBytes mos file rootObject |
rootObject := Array with: 123 with: 'abc' copy with: 2.44.

bytes := ByteArray new: 4000.
mos := MappedObjectStream on: bytes.
mos nextPutAll: rootObject. " add the object to serialize "
mos setLimit. " truncate the stream "
mos saveFile. " serializes and writes the class directory "

" copy the data to a new byte array "
newBytes := ByteArray new: mos size.
mos copyFrom: 0 to: mos size into: newBytes.

" write the byte array to a file for demonstration purposes "
file := File createFile: 'test.bin'.
file nextPutAll: newBytes.
file close.

2. To load an object:

| newBytes mos file |
file := File openFile: 'test.bin'.
file setToEnd.
newBytes := file contents.
file close.

" newBytes contains the data "
mos := MappedObjectStream on: newBytes.
mos updateObjects
" the root object remains accessible as long as newBytes
is referenced.


Method Consistency Check

The code below recompiles all methods without installing them. This allows you to detect compilation errors (for example, undefined constants, deleted classes or other inconsistencies).

| compiler oldProgress |
oldProgress := nil.
progressIndicator notNil ifTrue: [
oldProgress := progressIndicator.
].
progressIndicator := ProgressDialog new openModelessIn: NULL title: 'Recompiling Methods'.

compiler := (Smalltalk at: #CompilationContext) new.
Compiler resetNil.
Compiler iterateOn: Object with: [ :md |
(md source indexOfString: SOURCE_NOT_AVAILABLE) == 0 ifTrue: [
progressIndicator setText: md printString.
Compiler load: md source
class: md smalltalkClass
category: md category
timeStamp: md timeStamp
on: compiler.
].
true
].
progressIndicator close.
oldProgress notNil ifTrue: [progressIndicator := oldProgress ].