About This Article
I want to give people a basic idea of how plugins should work and what kinds of ways they can be made and used. (There will be no exact coding because that is very different in every case.)
What Are Plugins?

About This Article
I want to give people a basic idea of how plugins should work and what kinds of ways they can be made and used. (There will be no exact coding because that is very different in every case.)
What Are Plugins?
Plugins are pieces of code (often ATLs or.NET DLLs) that intergrate with a host application, by being in a certain folder or being registrated, and has (partial) control of the execution of the host program.
Not all plugins are meant to change the whole host that much as in MDE. Sometimes, plugins are just for simple routines. For example, take milkshape3d. Milkshape3d is a 3d model editor; milkshape3d plugins can add new "save as.. filetypes".
What Are the Advantages of Plugins?
- They are very portable and easy to deploy. You have to put a DLL in the plugin folder, or register it with a.reg file.
- They are small. Plugins are very small, but can pack enormous power.
- And more, but that depends on the plugin framework that is used!
Making Your Own Plugin Framework
Making a plugin framework isn't hard. It is very easy, when you do it right. Before you can make it, you must make a plan for it. What has it got to do, what do I want it to let do... These are the plugin framework types you can consider:
- A small plugin framework that lets plugins add one or a few new options. For example, new menu items in the 'export as' menu.
- Medium scale plugin framework that lets the plugins add features to the host application, such as new forms, new menu items, and changing the host.
- Big scale plugin framework. This has to be totaly plugin based, which means that the host just loads the plugins, and then lets the plugins do what they have to do.
There is a big difference. Making a small plugin framework that just adds a new option in, for example, a menu is not hard to program, but it keeps plugins very limited. It also requires much less coding, and there aren't many things to go wrong.
Small Plugin Framework
Here is an example of a small plugin framework (note that I left big gaps; that's because it is meant as an example, written in VB 6).
'code for the mainform of an application sub LoadPlugins 'this will be the sub launched when the plugins have to load dim plugins as new collection plugins = getdllsfromfolder (app.path + "\plugins") 'I won't write down this function because it has nothing to do 'with plugins dim plugp as string dim plug as object for each plugp in plugins set plug = createobject (getbasename(plugp) + ".pluginmain") 'creates an instance of the pluginmain class in the plugin dll. plug.addmenuitems (me) 'will let the plugin be able to run the 'addmenu item sub in this form by 'passing the object reference next end sub sub addmenu(caption as string, key as string) 'this sub is run by a plugin when it wants to create a menu. redim preserve MNUPlugins(ubound(MNUPlugins)+1) set MNUPlugins(ubound(MNUPlugins) = new menuitem MNUPlugins.caption = caption MNUPlugins.tag = key 'this is the key used to let the plugin 'know that the menu item is pressed end sub public sub MNUPlugins_click(index as long) 'This is just a copy of the previous code for getting the 'plugins. This isn`t a good way to do it 'The best way is to store it in arrays dim plugins as new collection plugins = getdllsfromfolder (app.path + "\plugins") 'I won't write down this function because it has nothing to do 'with plugins dim plugp as string dim plug as object for each plugp in plugins set plug = createobject (getbasename(plugp) + ".pluginmain") 'creates an instance of the pluginmain class in the plugin DLL. plug.menuitempressed(MNUPlugins(index).tag) 'All plugins are warned that a menu item is pressed and the 'plugins which has made the menu item (which it can identify 'because it has left a key, which is now returned, can respond next end sub '----CODE FOR THE PLUGIN DLL's class pluginmain---- public sub addmenuitems(host as object) host.addmenu("Some menu caption", "somemnucpt") end sub public sub menuitempressed(menukey as string) select case menukey case "somemnucpt" msgbox "pressed" end select end sub
As you can see, that plugin framework does its job, but is very static.
Medium scale plugin framework
Here is the code of a plugin of FL Studio. FL Studio is a program by Micheal Houston and me and may not be copied in any way. (The code is in VB.NET 2003.) As you can see, the plugins have more room, but still can't do everything.
Imports System.Windows.Forms Public Class myPlugin Implements FLStudio.IFLStudioPlugin Private studio As FLStudio.IFLStudio Private myMenu As MenuItem Private myTab As TabPage Public Sub initialize(ByVal FLStudio As FLStudio.IFLStudio) _ Implements FLStudio.IFLStudioPlugin.initialize studio = FLStudio myMenu = New MenuItem("Test Plugin") studio.addMenu(myMenu) myTab = New TabPage("Test Tab") studio.addTab(myTab) End Sub 