Please Help - Need Plugin Advice!! 
Author Message
 Please Help - Need Plugin Advice!!

Hi,

I am just getting into programming and vb.net and was hoping someone
could point me into the right direction. I want to be able to create a
number of plugins that all share the same interface and I want my
program to scan a folder for files and then activate any that exist.
But I don't want any preregistration of these plugins with the system
first, just drag and drop into folder and then restart the
application.

Is there some technology out there that already does this? If not can
someone please give me any hints on how to start?

Thanks in advance,

AJB



Fri, 14 Oct 2005 02:01:26 GMT  
 Please Help - Need Plugin Advice!!
Hello,


Quote:
> I am just getting into programming and vb.net and was hoping someone
> could point me into the right direction. I want to be able to create a
> number of plugins that all share the same interface and I want my
> program to scan a folder for files and then activate any that exist.
> But I don't want any preregistration of these plugins with the system
> first, just drag and drop into folder and then restart the
> application.

Samples:

http://www.vbsource.net.ms/dotnet/samples/techniques/
-> sample "PlugIns"

The sample is commented in German, nevertheless it is really easy to
understand.

Regards,
Herfried K. Wagner



Fri, 14 Oct 2005 02:05:06 GMT  
 Please Help - Need Plugin Advice!!
Hi AJB.

Quote:
>Is there some technology out there that already does this? If not can
>someone please give me any hints on how to start?

Yes, the Reflection technology is the way to go.

In .NET, reflection provides infrastructure to implement late binding. You
can define an interface and implement this interface in all your plugins.
In your application, dynamically load these pluggins assemblies by using
the Assembly.LoadFrom method and call the CreateInstance method to
intialize the class you want. Cast the class to the comman interface you
defined, and then you can call the methods on this interface.

Hope this helps.

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Quote:

>Newsgroups: microsoft.public.dotnet.languages.vb
>Subject: Please Help - Need Plugin Advice!!

>X-Newsreader: Forte Agent 1.91/32.564
>MIME-Version: 1.0
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit
>Lines: 16

>X-Abuse-Info: Please be sure to forward a copy of ALL headers
>X-Abuse-Info: Otherwise we will be unable to process your complaint
properly.
>NNTP-Posting-Date: Sun, 27 Apr 2003 13:50:42 EDT
>Date: Sun, 27 Apr 2003 19:01:26 +0100
>Path:

cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!c03.atl99!news.webusene
t.com!pc01.webusenet.com!fe07.atl2.webusenet.com.POSTED!not-for-mail

- Show quoted text -

Quote:
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:104181
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb

>Hi,

>I am just getting into programming and vb.net and was hoping someone
>could point me into the right direction. I want to be able to create a
>number of plugins that all share the same interface and I want my
>program to scan a folder for files and then activate any that exist.
>But I don't want any preregistration of these plugins with the system
>first, just drag and drop into folder and then restart the
>application.

>Is there some technology out there that already does this? If not can
>someone please give me any hints on how to start?

>Thanks in advance,

>AJB



Fri, 14 Oct 2005 11:59:59 GMT  
 Please Help - Need Plugin Advice!!

Quote:
> Hi,

> I am just getting into programming and vb.net and was hoping someone
> could point me into the right direction. I want to be able to create a
> number of plugins that all share the same interface and I want my
> program to scan a folder for files and then activate any that exist.
> But I don't want any preregistration of these plugins with the system
> first, just drag and drop into folder and then restart the
> application.

> Is there some technology out there that already does this? If not can
> someone please give me any hints on how to start?

> Thanks in advance,

> AJB

Here is code for loading plug-in type .dll that works for me.  May not be
the best solution, but is fairly easy.  It uses reflection to query a
.dll and see if it implements a certain interface:

This function loads the first class it finds in the .dll that implements
the interface.  If there are more than one then you will have to alter it
as appropriate.  Also, the exception handling is very generic.  It could
probably use some tweaking.

Pass the path\filename of the .dll to this function and it will return
and instance of the plugin (interface)

'loads the first class that implements the interface
Public Function LoadFromAssembly(ByVal AssyName As String) As IPlugin

   Dim aTypes() As Type
   Dim aIntf As Type
   Dim oAss As [Assembly]

   Try
      oAss = [Assembly].LoadFrom(AssyName)

      aTypes = oAss.GetTypes()
      For Each aIntf In aTypes
         'If this class implements the interface
         If Not (aIntf.GetInterface("PlugLib.IPlugin") Is Nothing) Then
            'Return an instance of the class
            Return CType(oAss.CreateInstance(aIntf.FullName),
PlugLib.IPlugin)
            Exit For
         End If
      Next
   Catch e As Exception
      MsgBox("Error loading plugin [" & Path.GetFileName(AssyName) & "]:
" & e.Message)
      Return Nothing
   End Try
End Function

This may not be exactly what you need, but it should give you some ideas.

Chris

--
If you don't like lunchmeat, please remove it from my e-mail address to
send me an e-mail



Fri, 14 Oct 2005 23:38:37 GMT  
 Please Help - Need Plugin Advice!!
Thanks to everyone that replied! Will go through this stuff and give
it a go!

:)

AJB

On Mon, 28 Apr 2003 08:38:37 -0700, Chris Dunaway

Quote:


>> Hi,

>> I am just getting into programming and vb.net and was hoping someone
>> could point me into the right direction. I want to be able to create a
>> number of plugins that all share the same interface and I want my
>> program to scan a folder for files and then activate any that exist.
>> But I don't want any preregistration of these plugins with the system
>> first, just drag and drop into folder and then restart the
>> application.

>> Is there some technology out there that already does this? If not can
>> someone please give me any hints on how to start?

>> Thanks in advance,

>> AJB

>Here is code for loading plug-in type .dll that works for me.  May not be
>the best solution, but is fairly easy.  It uses reflection to query a
>.dll and see if it implements a certain interface:

>This function loads the first class it finds in the .dll that implements
>the interface.  If there are more than one then you will have to alter it
>as appropriate.  Also, the exception handling is very generic.  It could
>probably use some tweaking.

>Pass the path\filename of the .dll to this function and it will return
>and instance of the plugin (interface)

>'loads the first class that implements the interface
>Public Function LoadFromAssembly(ByVal AssyName As String) As IPlugin

>   Dim aTypes() As Type
>   Dim aIntf As Type
>   Dim oAss As [Assembly]

>   Try
>      oAss = [Assembly].LoadFrom(AssyName)

>      aTypes = oAss.GetTypes()
>      For Each aIntf In aTypes
>         'If this class implements the interface
>         If Not (aIntf.GetInterface("PlugLib.IPlugin") Is Nothing) Then
>            'Return an instance of the class
>            Return CType(oAss.CreateInstance(aIntf.FullName),
>PlugLib.IPlugin)
>            Exit For
>         End If
>      Next
>   Catch e As Exception
>      MsgBox("Error loading plugin [" & Path.GetFileName(AssyName) & "]:
>" & e.Message)
>      Return Nothing
>   End Try
>End Function

>This may not be exactly what you need, but it should give you some ideas.

>Chris



Sat, 15 Oct 2005 18:16:50 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Please help...Need advice how to do a screensaver with VB6

2. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

3. Please help me!! ABOUT A OUTLLOK PLUGIN APPLICATION

4. IE Plugin Help needed

5. IE Plugin Help needed

6. IE Plugin Help needed

7. IE Plugin Help needed

8. IE Plugin Help needed

9. High level advice needed....please

10. TOTALLY NEW TO PROGRAMMING!!!! Need Advice Please :-)

11. Need newbie advice please

12. PLEASE: I need your advice...

 

 
Powered by phpBB® Forum Software