Enough of the boring stuff, let's write some code!

Implementing the PowerPatcherInterop interface

The PowerPatcherInterop interface is what shouts out "HEY POWERPATCHER! I'M HERE, AND I'M AN ADD-IN!" There must be only one class that implements this interface per add-in. (If no class does, PowerPatcher simply won't load the add-in. Conversely, if multiple class implement the interface, PowerPatcher will load all those classes as add-ins. This is usually bad. For the curious: yes, it means you can squeeze multiple add-ins into one DLL, though this is frowned upon)

So how do we go about doing this? Easy! First, open the "Class1.cs" file under your add-in. It should look similiar to this this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SampleAddIn
{
    public class Class1
    {
    }
}

Rename Class1 to something more descriptive, like your add-in name. Now, add the following after the name: " : PowerPatcherInterop.iPlugIn". Now, right click on "iPlugIn" and select Implement Interface > Implement Interface. Your code should now look like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SampleAddIn
{
    public class SampleAddIn : PowerPatcherInterop.iPlugIn
    {
        public System.Windows.Controls.UserControl GetAddInUI()
        {
            throw new NotImplementedException();
        }

        public Guid GetGUID()
        {
            throw new NotImplementedException();
        }

        public void Initialize(PowerPatcherInterop.InitInfo info)
        {
            throw new NotImplementedException();
        }

        public string Name
        {
            get { throw new NotImplementedException(); }
        }

        public void RunPlugin()
        {
            throw new NotImplementedException();
        }
    }
}

Implementing the methods

Hmmmmm.... those NotImplimentedExceptions could be a problem. Let's fix a few...

GetGUID

Simply change that method to the following:
        Guid _guid;
        public Guid GetGUID()
        {
            return _guid;
        }

You'll notice we didn't initialize _guid. That comes next, in the

Initialize Method

This is where you'll want to place all of your add-in initialization code. Think of it as "OnAddInLoad".

For now, replace it with this:

        PowerPatcherInterop.InitInfo _info;
        public void Initialize(PowerPatcherInterop.InitInfo info)
        {
            _info = info;
            _guid = Guid.NewGuid();
        }

Note the InitInfo class. This is a bundle of useful information that PowerPatcher sends your add-in. Explore it, and use it.

Name

This is self explanatory. Replace the throw statement with a return "Your Add-in name here".

Run Plugin

This is what PowerPatcher calls to autorun plugins. It should invoke the primary feature of your add in. For now, leave it blank.

GetAddInUI

This is what PowerPatcher calls to fill the tab allocated for your add in. We'll revisit it in the next section. Fir now, leave it blank.

Last edited Apr 14, 2012 at 11:22 PM by Xcelled194, version 1

Comments

No comments yet.