Using the Help Builder Automation Classes

Using the classes is easy. You can access them from any .NET application. Follow these steps:

  • Make sure Help Builder is installed
  • Add a reference to wwReflection20.dll to your project
  • Add the Westwind.wwHelp and Westwind.wwReflection namespaces
  • Use wwHelp.CreateInstance() or wwHelpForm.CreateInstance()
  • Fire away on the objects

Alright. Let's see some code. The following code creates a new project and adds a few topics into it. We'll then open the IDE and display the new project. Here it is:

using Westwind.wwHelp;

...

private void cmdHbAutomation_Click(object sender, System.EventArgs e)
{
	string Pk = "";
	string Project = @"d:\temp\SampleProject\SampleProject.hbp";

	wwHelp Hb  = wwHelp.CreateInstance();

	using(Hb) 
	{
		Hb.CreateProject(Project,
			"Sample Project","West Wind");

		// *** Add a new topic underneath the root
		Hb.NewTopic();
		Hb.Topic.Body = "Hello world from the new topic.";
		Hb.Topic.Topic = "Root Child Topic";
		Hb.Topic.Type = "TOPIC";
		Hb.Topic.ParentPk = "INDEX";  // Root topic is Index
		Hb.SaveTopic();

		Hb.NewTopic();
		Hb.Topic.Body = "This is the User Guide Topic";
		Hb.Topic.Topic = "User Guide";
		Hb.Topic.Type = "HEADER";
		Hb.Topic.ParentPk = "";   // Top level topic
		
		Hb.SaveTopic();
		
		// *** Save the Pk
		Pk = Hb.Topic.Pk;

		// *** Create a child topic
		Hb.NewTopic();
		Hb.Topic.Topic = "User Guide Child Topic";
		Hb.Topic.Body = "User Guide Child Topic Detail text";
		Hb.Topic.Type = "TOPIC";
		Hb.Topic.ParentPk = Pk;  // *** saved pk

		Hb.SaveTopic();
		
		Hb.Close();
		// Hb.Release();  // Release COM object 
	}
}

The above code creates a new project and adds a few topics to it. Note the use of the using() pattern to get the object to release its underlying COM reference. It's vital that you either call Hb.Release() (commented out below) or you use the using construct in C# to force the object to unload.

If you want to preview the project you just create you can add code like the following to the above:

    	// *** Now lets view it in a Help Builder Form
	wwHelpForm hbForm = wwHelpForm.CreateInstance();
	
	hbForm.Top = 10;
	hbForm.Left = 10;
	hbForm.Width = 800;
	hbForm.Height = 600;

	hbForm.Open(Project);

	hbForm.Show();  // make form visible
	
	hbForm.GoTopic(Pk);   // Go to User Guide topic saved above

	// *** Retrieve content of this topic
	string Body = hbForm.Help.Topic.Body;

	MessageBox.Show("Body content of current topic:\r\n" + Body + "\r\n\r\n" +
                               "Check your project and press Ok to exit");

	// *** Explictly Release COM object
	hbForm.Release();

As you can see it's real simple to automate Help Builder and create content with it dynamically, then manipulate the IDE to some degree.

Com Instance Reference

Note that not the entire COM interface is exposed via the .NET wrapper. We've basically exposed the main features and 'hidden' the more esoteric interface elements that are meant primarily for internal use. However you can get at those elements via the underlying ComInstance reference that is available on each of the objects. This reference can be accessed with Reflection to retrieve the full COM interface.

© West Wind Techologies, 2018 • Updated: 08/08/07
Comment or report problem with topic