Link to home
Create AccountLog in
Avatar of prefix
prefix

asked on

Who can give me a entire example of this,please?

I want to write a program that support plugins, but I don't know how to do this. The program will like Winamp, if I copy some new DLL(Plugins) into the plugin directory, the program will get some new feature in itself, and I needn't to amend the program.
I'm sorry that I can only give you such few points,but I'm new, my points is less and less. I'll thank all who can help me this.Thanks!
Avatar of Marine
Marine

Putting that programms dll won't help you. You will need to enhance your Interface to do so. Meaning that without changig your code to implement the dll functions your programm won't be using these methods. There is no way of you doing this without always enhancning the interface,adding something and then recompling it.
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of prefix

ASKER

Thanks! Did you make a program like this? Do you mind posting it or the part about this question of your program to me,please? Thank you.
Sorry, I didn't write the program... Just passing on information to you.

Cheers!
Avatar of prefix

ASKER

I don't mind.
Avatar of prefix

ASKER

Oh~~~it's a long time since then.
Can I make a program with a open plugin port like winamp? For example(only example): I make a winamp, but the plugin port how I can do? The winamp we can copy the plugins into the directory where the winamp plugins in,and then choose a plugin(and its name can also be shown to us),then press Ctrl+Shift+K,the plugin can be activated,but before I copy the plugin into,winamp didn't know there's a plugin there,and didn't know when and how to send message to active the plugin.How to make it possible??
Thanks very much. This is important to me.


It is possible to write a plugin interface for VB.

1. You need to build the Plugins. therefor build a new activex dll Project and create a class named "clsPlugin" (this is the interface, and has to be public). Put as many Properties and Methods in this class, but remember, that you have to put this Methods and Properties in every Plugin. For e.g. we will put two functions called "Start" and "Stop" in this module.

2. Name the Project "Plugin1" and compile it to "Plugin1.dll". Warning the Projectname, has to be the same like the filename without the extension.

3. Now you can build a second Plugin called "Plugin2" and so on.

Now you need to extend your application with a module, wich will do the following:

4. Check a specified directory for the *.dll files

5. Fill an array of objects, with the following method

set objPlugin(intI) = CreateObject(strPluginClass)

strPluginClass = Filename without Extension (e.g. Plugin1.dll = Plugin1) and ".clsPlugin"

strPluginClass will be "Plugin1.clsPlugin" for our first sample and "Plugin2.clsPlugin" for our second sample.

6. You can call the Methods, with the following Line

objPlugin(intI).Start or
objPlugin(intI).Stop
Avatar of prefix

ASKER

Great!
Thank You VERY MUCH.

Cheers!!!
BUILD THE APPLICATION

1. Create a Standard-Exe Project

2. Create a Form and place three command buttons on it (command1, command2 and command3). After that place the following code into the module:

Private objPlugin() as Object

Private Sub Command1_Click
  Dim strFile as String

  strFile = Dir(App.Path & "\Plugins\*.dll")
  Do Until strFile = ""
    ReDim Preserve objPlugin(UBound(objPlugin()+1))
    Set objPlugin(UBound(objPlugin())) = CreateObject(Left(strFile, Len(strFile) - 4) & ".clsPlugin")
    strFile = Dir()
  Loop
end Sub

Private Sub Command2_Click
  Dim intI as Integer

  For intI = 1 to ubound(objPlugin())
    Msgbox "My Name is " & objPlugin(intI).Title
  Next
End Sub

Private Sub Command3_Click
  Dim intI as Integer

  For intI = 1 to ubound(objPlugin())
    Call objPlugin(intI).SaySomething
  Next
End Sub

3. Compile it and copy Project1.exe to "c:\test"

4. Create a subdirectory called "Plugins"


BUILD THE PLUGIN

5. Create an ActiveX-DLL Project and name the Project "Plugin1"

6. Create a class called "clsPlugin"

7. Put the following code into the class

Public Function Title() as String
  Title = "Billy"
End Function

Public Sub SaySomething
  Msgbox "There is nothing to say"
End Sub

8. Save it and compile it to "Plugin1.dll"

9. Copy the file "Plugin1.dll" into "c:\test\Plugins" and start "Project1.exe"

That's it. If you want to create another Plugin step 5 to 9 again and give them an unique name and the same filename.


I hope, that that code will help you ;-)

Dirk
Avatar of prefix

ASKER

d hottes:
I feel very happy.
Yes, thank you again...again. (~O~)..