Results 1 to 11 of 11

Thread: [RESOLVED] [2005] Plug-in capability

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    In front of my pc
    Posts
    78

    Resolved [RESOLVED] [2005] Plug-in capability

    I think this is possible, I only haven't got a clue how to do it and I think it will be hard to explain.

    I want to make an application with several kinds op plug-ins, one for example for input(keyboard, gamepad, etc.) and another kind for file-playback (mp3, wma, etc). I don't care about the codes in these classes, I only care about their events and functions, those have to comply to the functions/events my application uses. I want the user to be able to enable/disable plug-ins and add them by a browse button (so it have to be dll's). The question is, how the heck do I do this?

    Thanks in Advance,

    GtheMan
    Last edited by gtheman; May 8th, 2006 at 11:46 AM. Reason: added [2005] tag

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Plug-in capability

    You would be better of reading about Plug-in Based Architecture for Windows Applications

    This article explains the concept and how to implement it.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    In front of my pc
    Posts
    78

    Re: Plug-in capability

    Thanks!

    That's exactly what I was looking for

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    In front of my pc
    Posts
    78

    Re: Plug-in capability

    Hey guys, I made a new project with the class from the link of Shuja Ali, so I can add plugins. Now, I want to be able to add the plugins which have been found to an array(list), so I can use them all. When I do this, I get an error:


    VB Code:
    1. Dim objFilePlugin As Interfaces.FilePlayer
    2. Dim objFilePlugins() As Interfaces.FilePlayer
    3.  
    4. Dim strFolder as String = Inputbox("Give me the folder containing the plugins!")
    5. FilePlugins = PluginServices.FindPlugins(strFolder, "FilePlayer")
    6.  
    7. Console.WriteLine("Found " & FilePlugins.Length.ToString & " file-playback plugins:")
    8. For x As Integer = 0 To FilePlugins.Length - 1
    9.     objFilePlugin = DirectCast(PluginServices.CreateInstance(FilePlugins(x)), Interfaces.FilePlayer)
    10.     objFilePlugins(x) = objFilePlugin
    11.     Console.WriteLine("   " & objFilePlugin.Name)
    12. Next

    In the line
    VB Code:
    1. objFilePlugins(x) = objFilePlugin
    I get a NullReference exception (Object reference not set to an instance of an object.) When I only use the first plugin found and do not add it to a array(list), it works perfectly. What am I doing wrong?

    Thanks in Advance,

    GtheMan

  5. #5
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Plug-in capability

    You are defining an Array, but are not initializing it.
    VB Code:
    1. Dim objFilePlugins() As Interfaces.FilePlayer
    You will need to initialize the array before you could use it. In your case you will use ReDim statement like this before the for loop.
    VB Code:
    1. ReDim objFilePlugins(FilePlugins.Length)
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    In front of my pc
    Posts
    78

    Re: Plug-in capability

    *GtheMan hits himself in the middle of his face because he feels stupid*

    Anyway, Thanks Shuja Ali, you're really helping me out!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    In front of my pc
    Posts
    78

    Re: Plug-in capability

    Lol, here I am again, with yet another question (I'm getting sick of not knowing things )

    I now have several working plugins, but I still have to make a way for them to communicate with their host-application (a form in this case). I tried this by making events in the interface, which get called by the dll... They do get raised by the dll, but they never arrive in the main application. How come?

    VB Code:
    1. Dim FilePlugins() As PluginServices.AvailablePlugin
    2.     Dim InputPlugins() As PluginServices.AvailablePlugin
    3.     Dim GuiPlugins() As PluginServices.AvailablePlugin
    4.  
    5.     Dim objFilePlugins() As Interfaces.FilePlayer
    6.     Dim objGuiPlugins() As Interfaces.GUI
    7.     Dim objInputPlugins() As Interfaces.Input
    8.  
    9.     Dim WithEvents GUI_Events As Interfaces.GUI

    VB Code:
    1. Implements Interfaces.GUI
    2.  
    3. Public Event Command(ByVal command As String, ByVal argument As String) Implements Interfaces.GUI.Command
    4.  
    5.     Private Sub frmGUI_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    6.         RaiseEvent Command("end", "")
    7.     End Sub
    The code above does not produce any errors. The RaiseEvent line gets called, but never 'arrives' in the code below:
    VB Code:
    1. Private Sub GUI_Command(ByVal strCommand As String, ByVal strArgument As String) Handles GUI_Events.Command
    2.         Command(strCommand, strArgument)
    3. End Sub

    Again, I think I'm doing something wrong, but what?

    I've had these kinds of problems with events a lot in VB.Net 2005 (don't know if it worked well in vb6, because I never realy used events in vb6...)

    Thanks in Advance,

    GtheMan
    Last edited by gtheman; May 8th, 2006 at 12:13 PM. Reason: typo

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: [2005] Plug-in capability

    Here are some other posts on the subject:
    http://www.vbforums.com/showthread.php?t=194447
    http://www.vbforums.com/showthread.php?t=275145

    There used to be a really good one by Cander but I can't find it now.

    You are probably not using AddHandler for each instance in the array.
    Somewhere during creation you should be adding handlers for the events you want.
    VB Code:
    1. 'something like this
    2. Console.WriteLine("Found " & FilePlugins.Length.ToString & " file-playback plugins:")
    3. For x As Integer = 0 To FilePlugins.Length - 1
    4.     objFilePlugin = DirectCast(PluginServices.CreateInstance(FilePlugins(x)), Interfaces.FilePlayer)
    5.     objFilePlugins(x) = objFilePlugin
    6.     AddHandler Host.Command, objFilePlugin.Command
    7.     Console.WriteLine("   " & objFilePlugin.Name)
    8. Next

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    In front of my pc
    Posts
    78

    Re: [2005] Plug-in capability

    Thanks a lot Edneeis, I didn't know about the addhandler yet I guess I've still got a lot to learn

    GtheMan

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: [RESOLVED] [2005] Plug-in capability

    Just some advice.. it is really really a bad idea to use an inputbox to ask for a directory name. (generally speaking the input box is horrible for anything other than asking for the simpliest of string variables)

    you can use built in controls in the .NET framework, like the FolderBrowseDialog (which is located in the toolbox) to have the user browse for a specific folder on the system.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    In front of my pc
    Posts
    78

    Re: [RESOLVED] [2005] Plug-in capability

    I do know about the dialogs(OpenFileDialog etc.), I just used the inputbox to test the code(put it together real quick) Anyways, thanks for trying to help me!

    Maybe I'll post a link of my mediaplayer as soon as it's ready for testing(at least, when it's any good). Features I'm working on are:
    - plugin support for audioplayback, you can write plug-ins for any (media) filetype you want
    - Multiple GUI capability: you can do anything you want on a GUI as long as it's in visual studio.net 2005, because it does have to 'support' the interface.

    I hope it'll work out good, until now it looks quite promissing
    Last edited by gtheman; May 10th, 2006 at 12:50 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width