PiecesProgram Pieces

Chapter 2: Hello, World!

EastridgeHow to build a simple program piece

This tutorial will build a simple program piece with one function: to show a dialog box with the famous, "Hello, world!" phrase.

We will build a new project with a class that inherits from the IProgramPiece interface. Then we implement the function OnCallBeforeShow() to simply display a MessageBox saying, "Hello, World!"

Create a project

Start a new "class library" project in Microsoft Visual C# or Visual Basic. We will call this PPHelloWorld.

new project

Add references

Right click on References (in the Solution Explorer window) and browse to the directory where the Mountain Meadow program resides on your computer to add a reference to MM3Common.dll This normally resides in the main program files folder for Mountain Meadow, e.g., c:\Program Files\EastRidges\MM3

(Please be aware your project will need to be recompiled any time MM3Common.dll is recompiled. At the time of this writing it is recompiled frequently but eventually it should stay unchanged for a year at a time. MM3Common.dll will not necessarily be recompiled with every MountainMeadow3 update.)

{short description of image}

Now you have a project with one default class called Class1.

{short description of image}

Right-click Class1.cs in the Solution Explorer and rename it to HelloWorldProgramPiece.

In order to show a dialog form with the message, add a reference to Windows Forms to our project. Right click References, then Add References, and choose System.Windows.Forms under the .NET tab:

{short description of image}

Within the HelloWorldProgramPiece class, add the following code:

Add a "using" statement to make the MM3Common types show up in the "intellisense" function of the Visual Studio environment and make our job easier:

using MM3Common;

Sign the assembly

Right click the project in Solution Explorer and then select Properties to open the project properties dialog:

sign the assembly

Inside the Signing tab you can use your own pre-created key or let Visual Studio create a key for you.

Implement the IProgramPiece interface

We can implement the IProgramPiece interface manually or by inheriting from a pre-made implementation called ProgramPieceBase. If you just type ," :IProgramPiece" to indicate inheritence, Visual Studio offers to build the method stubs to let you implement the interface automatically. However, to make things simpler, we will inherit from the ProgramPieceBase object is available in the MM3Common namespace that already implements all those methods. That way we don't have to write any code except to override the methods we want to change:

We will override the OnCallBeforeShow() method to show our message:

public override void OnCallBeforeShow(string[] parameters)
{
System.Windows.Forms.MessageBox.Show( "Hello world, from my program piece!");
}

The project should look something like the illustration below, except that you changed Classs1 to HelloWorldProgramPiece:

{short description of image}

That should do it. Press F6 to compile the project and make note of where the output file, "PPHelloWorld.dll" resides. Copy that component file to the Mountain Meadow program directory and use the administrator's program MM3Admin.exe to attach it to the program.

Try it out

To run the program, start Mountain Meadow and click the menu option Tools, Windows, MyPiece (or whatever you named it when in administrator's console).

{short description of image}

Next tutorial: Accessing data: PPHelloUser.htm