|
-
Jun 26th, 2007, 08:07 AM
#1
Thread Starter
Hyperactive Member
[2005] Loading Pluggins/DLL files, DirectCast
I want to make a pluggable architecture for my media player, and Im not sure about how to load the DLL files...
How do I load a dll and assign it to a variable I have heard of something like "LoadAssembly"????
I know that once I load all the DLL files in my plugin directory I can use DirectCast in a try catch to check if the DLL file is of the type I want. Is it ok to use DirectCast like this (After I figure out loading the DLLs)...
Code:
Sub LoadDLLs
Dim lstDLL as list of player 'Player is an interface that the DLL file I want should implement, Can I use an interface like this too?
For each DLL file in pluggin directory 'Sudo code
dim obj as object= loadplugin(DLL.path) '"LoadPlugin? How do i do this
try
Dim playa as new player = DirectCast(obj, player)
lstDLL.add(playa)
catch e as exception
'No need to do nothing for a dLL that isnt what I want
end try
End Sub
Any help would be appreciated heaps, I can only find one source of info for this and although it is simple it just isnt up to begginer introduction standards (well in the descriptive meaning) It just doesnt explain enough, So I thaught I would try and build my understanding from the ground up starting with loading the assemblies...
Please help, there just isnt enough info on this...
-
Jun 26th, 2007, 09:54 AM
#2
Re: [2005] Loading Pluggins/DLL files, DirectCast
Here's something that I use. Rather than looping through a directory as you have done, I use an xml file specify the location of the dll, and the classname
vb Code:
Imports System.Runtime.Remoting
'...
'create object reference to assembly
Dim handle As ObjectHandle = _
Activator.CreateInstanceFrom(drAssembly.Path, drAssembly.ClassName)
Dim processor As IFileProcessor = DirectCast(handle.Unwrap(), IFileProcessor)
'Call the assembly to process the file
processor.ProcessFile(fileParms.FullPath, hsParms)
-
Jun 26th, 2007, 05:14 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] Loading Pluggins/DLL files, DirectCast
Sorry to be annoying, but could you explain what these methods are doing in sequence if you could (I dont have access to visual studio, normally intellisence and help gets me through but I cant use it at the moment)...
Why is objectHandle used rather than Object?
What is Activator?
I guess the class name will have to include namespace as well(eg: MediaNameSpace.Player), Can all classes I load have the same class name?
I get the rest I think, IFileProcessor is an interface you have declared that the class will implement, Correct or not?
Once you have that, the rest is easy, right, can you treat the "processor" object like any other variable that was initialized in a more conventional way.
Here is the reason behind of all this.
I am making a media player, and because I dont have the masterfull math skills required to make audio decoders and players myself, I decided I will make it pluggable, so that I can write the first plugin using the WMP active X control, this way my code can be compilled in mono aswell and hence I will have cross platform operabitlity(After I or someone else makes plugins that will run on linux etc), I am also making it skinnable and pretty much all functionality will be pluggable from library, now playing, to sound output modifiers, burners, rippers, ect. All I have to do, is First figure how to load assemblies, then figure out how to communicate with them (which is trivial)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|