How do I create a HotDocs plug-in using Visual C#?

To create a HotDocs plug-in using Visual C#

  1. Create a new Visual C# Class Library project.
  2. Right click on References from the Solution Explorer and Add Reference.  The Add Reference dialog box appears.
  3. From the COM type libraries, select the HotDocs 11 Type Library. Click OK.
  4. Add a using HotDocs; statement to the project.

If you are using the example below you will also need to add using System.Runtime.InteropServices statement and using System.Windows.Forms statement to the project. If you would like to work from the example code you can copy it into the project at this stage. If chose to copy the code then you will need to create your own GUID and replace the example GUID where ever it appears in the example, generate property stubs for Cmd1 and Cmd2, and replace the sample icon location with the real location of your chosen icon.

  1. In the project, select the interface(s) your plug-in will implement from the HotDocs type library.
  2. Right click to implement the interface: adds stub functions for each function of the selected interface.
  3. Write the necessary code to implement each function of the selected interface.
  4. Register the plug-in DLL with HotDocs by passing its CLSID to the PluginsClass.Register method. For example:
 HotDocs.Application app = new HotDocs.Application();
 app.Plugins.Register("{12345678-1111-2222-AAAA-DDDDDDDDDDDD}", "Sample Menu Plugin", 100, 1);  
  1. Right click on the project in the Solution Explorer and select Properties. On the Build tab check the box to Register for COM interop.
  2. Change the version to Release and build the solution to produce a COM server DLL.
  3. Locate the .dll in your visual studio project files and copy the COM server DLL to the folder where HotDocs is installed.
  4. In an elevated command line using RegAsm register the DLL with Windows. For example:
C:\>Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe "C:\Program Files (x86)\HotDocs\WindowMenuExtension.dll" /codebase

Example

The following Visual C# example implements the ILibraryWindowMenuExtension interface:

[ComVisible(true)]
[Guid("12345678-1111-2222-AAAA-DDDDDDDDDDDD")]
public class WindowMenuExt : HotDocs.ILibraryWindowMenuExtension
{
    public void Command(string libraryPath, LibraryEntity caretEntry, int commandId)
    {        
if (commandId == cmd1)
System.Diagnostics.Process.Start("http://www.hotdocs.com");
if (commandId == cmd2)
MessageBox.Show("Menu sample w/icon selected");
}

public void DisplayMenuInitialize(string libraryPath, LibraryEntity caretEntry)
{
MessageBox.Show(caretEntry.Title);
}

public void GetMenuEntry(int menuPosition, ref string menuText, ref Icon Icon, ref bool enabled, ref bool callAgain, int commandId)
{
HotDocs.Icon icon = new Icon();
icon.LoadIcon(@"C:\images\MenuEntry.ico");

switch (menuPosition)
{
case 0:
menuText = "HotDocs Website";
enabled = true;
callAgain = true;
cmd1 = commandId;
break;
case 1:
//Add a separator
menuText = "-";
enabled = false;
break;
case 2:
menuText = "Menu Sample w/icon";
Icon = icon;
enabled = true;
callAgain = false;
cmd2 = commandId;
break;
default:
break;
}
}

public void GetMenuTitle(ref string menuTitle)
{
menuTitle = "Menu Ext Plugin";
}

public void Initialize()
{
//Do any one time initialization
}

public void LibraryInitialized()
{
MessageBox.Show("The library has been initialized");
}

[ComRegisterFunction]
public static void RegisterPlugin(Type t)
{
HotDocs.Application app = new HotDocs.Application();
app.Plugins.Register("{12345678-1111-2222-AAAA-DDDDDDDDDDDD}", "Sample Menu Plugin", 100, 1);
System.Runtime.InteropServices.Marshal.ReleaseComObject(app); }

[ComUnregisterFunction]
public static void UnRegisterPlugin(Type t)
{
HotDocs.Application app = new HotDocs.Application();
app.Plugins.Unregister("{12345678-1111-2222-AAAA-DDDDDDDDDDDD}");
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
}
}