tags:

views:

83

answers:

2

Hey Folks, I need to create a plug-in that updates an application. Look, I have a host application, but probably I will update it with to more functions. I am working in Windows with Delphi 7. Basically, "my plugin" should add 2 or 3 new functions to the host application. How can I program a plug-in (or a functionality) that inserts new code (new functions) in the host application without re-compiling it??

Note: I am sorry about my English. My natural language is Spanish.

Thanks anymore, Yulien.

+1  A: 

There are different ways to accomplish this, I will give you one of the most basic.

Say you are programming with C# on Windows (Other languages and environments are similar)

Part 1. You need to be able to load an assembly (if C++ a DLL). You might want to take this from a configuration file. Do this for every piece of functionality you want the plugin applications to extend.

Part 2. You need to be able to invoke code from this plugin, so put the functionality in an interface. For example, the main application will code to an interface IMyPluginCapability and your plugin will include some class which implements this interface. You can figure out which class through reflection.

Part 3. Invoke the functions you wish your plugin to extend.

Your language, environment will surely have similar capabilities. You can lookup details for that environment.

Tanmay
+2  A: 

You didn't specify the language or the platform on which you are working, so I can only give you a generic answer.

Plugins can be implemented in several different ways. The simplest (YMMV) is to compile the plugin to a Dynamically Linked Library (DLL in Windows) or a Shared Object (.so under Linux), and then you use the appropriate function to get specific functions from the DLL and call them.

Search the internet for the function LoadLibrary() on Windows or dlopen() on Un*x/Linux systems for more information.

An alternative is to embed a scripting language interpreter in your program. Firefox, for example, is implemented in C/C++ and exposes its internals to its JavaScript interpreter (SpiderMonkey) - in this way, all Firefox plugins can be written in JavaScript.

iWerner