I am still searching for the code to run a active x dll in runtime of my program. I want my program to have PLUG-In capability with ACTIVE X dll's but how can i do this? i have search all over the web only finding none working examples and 1 example that is just to big to find out how to do this ...
Plugins are a tricky thing because in order for the plugin to be useful it must interact with your program and in order for it to interact with your program your program has to expose things to it, but at design you don't really know what you need to expose. My theory was to make the program itself an activeX exe so the plugins can reference it and it can raise events in the plugin that way they have a means of knowing whats up. Also it can use an internal class for its own purposes and then expose that data to the plugins. Of course I made the example a while again and I did put comments in pretty good but there is no readme or anything else to explain it. None the less if you want to take a gander then your welcome to. I'll answer questions if you need, maybe it'll give you some ideas to make your own plugin system.
err i get a message while loading the active x dll you created:
Run-time error '492':
ActiveX component can't create object.
This is because i have to register the object first how to do this within VB? i know how to do it in a command prompt. And you told me i could make my program a activex program but will that change my program's capability's itself?
Also it can use an internal class for its own purposes and then expose that data to the plugins
i dont mind doing this because i want the user to be able to make plugins but not ofcourse use everything the program does :P so i must declare them or something?
Last edited by Ultimasnake; Aug 5th, 2002 at 06:20 AM.
I'm sorry I knew I should have looked it over before posting. The problem is that there is a circular reference at work here, because when the PlugApp loads the dll for its plugin the plugin also makes a reference to the PlugApp. This is fine unless a new GUID is made for the PlugApp since the Plugin DLL was made. Good news though if we switch the plugin DLL to late bind the PlugApp then all is well. So in the Plugin dll make the followiing change:
VB Code:
Private Sub Class_Initialize()
'Set gIFace = New PlugManager 'comment this line out
Set gIFace = CreateObject("PluginApp.PlugManager") 'and add this one
As for registering from VB I don't have any code that registers it as its loading, sorry. But I thought that Cander's plugin example did that so maybe you could incorporate that in. I'll see what I can do for ya, though. Yes this is the downside of the model because the plugins must be registered first, but after the change mentioned above that everything should work fine.
Also as far as switching from normal exe to active exe now they can work the same, the trick is in the Sub Main:
VB Code:
Public Sub Main()
'starts the application and shows the form
If App.StartMode = vbSModeStandalone Then frmMain.Show
End Sub
vbSModeStandAlone means it is being started as a normal exe not as an object so that is where you show your first form at.
Last edited by Edneeis; Aug 5th, 2002 at 10:35 AM.
ok i got the thing working.
I also made my own plugin program and a own hello world plug in. This works fine. But now i want to in example change the Form's caption to "test".
Do i have to put a function in the dll or in the program itself. and how to do this? have a little example for me on that? here is my program (very basic and hope it is ok) hope you can help me with a simple DLL :S
Now that I look at your test I see you already figured out how to register on the fly. As for changing the caption yes you'd have to add something in the 'PlugApp' class to expose the caption or a method either way. Maybe something like:
ok and how do i call these functions from a dll? and does my program HAVE to be an active x exe to work with the dll then? :S gonna eat now hope there is a responce when i am back
mind patching up a dll that does change the caption than? just to give me an idea? :S
Here is the caption change dll, and updated app that lets the caption be changed. That should shoe you how to call the functions from the dll, but basically its like working with any other object. See the gIFace in the example plugins is just a PlugManager object from the PluginApp and everything comes off of it. For instance it exposes the gIFace.Application object which in the PluginApp is the PlugApp class and serves as a container for anything you want to expose from the Application, like the form caption. The gIFace also expose the events from the application so you can respond to them in your plugin. And last it exposes the number of active plugins but it could expose the plugins themselves with a little more work. I didn't set that part up because I didn't know how useful it would actually be if the plugins could 'talk' to one another, but if you need it you could probably do it.
As for HAVING to be an activeX exe, if you want to expose parts of the application at runtime or do events I believe so. Being an activeX exe is what allows it to be an object and an application at the sametime and with the same instance so things change at runtime. So at least for this system to work then YES it has to be an activeX exe. Is there a reason you don't want it to be?
Ok so i changed my app to active x exe but i cant seem to run it anymore it gives me the error:
No creatable public component detected ..... how did you managed to change that in your app? cant seem to find it
oh and while compiling your DLL example i get the error data member not found @
appCaption = gIFace.Application.Caption
and it doesnt seem to work any more in your app either
Last edited by Ultimasnake; Aug 5th, 2002 at 11:52 AM.
By the way I had started to build in support to expose a toolbar as well but never finished it. Thats what the CAppBar and CAppButton classes are. That way plugins could add buttons to the toolbar of the app.
An activeX exe has to have at least one Public class.
Last edited by Edneeis; Aug 5th, 2002 at 11:51 AM.
To convert your existing application into a plugin type one (using this system) you'll also need to transfer the classes and module from the PlugApp into and change them to fit your app.
One good thing about this system is that to write a plugin all you need is the app (and maybe a help file). Because the plugin just makes reference to the app itself for the objects it needs and the rest is just like making any other dll.
Last edited by Edneeis; Aug 5th, 2002 at 11:53 AM.
Originally posted by Ultimasnake oh and while compiling your DLL example i get the error data member not found @
appCaption = gIFace.Application.Caption
and it doesnt seem to work any more in your app either
Did you compile the dll BEFORE the app? Or at least before you ran the app once so it registers itself? If so then the App didn't hace a Caption property yet, not until it is recompiled or the compiled one is reregistered (if i compiled it, can't remember).
'This object is becomes the global part that is shared among all plugs.
'Only methods and properties in this class are visible to all the plugs, it serves
'as somewhat of a go-between for the application in the activeX exe, frmMain in
'this case.
Public Enum AppReturnConstants
retFailed
retSuccessful
End Enum
Public Property Get Caption() As String
Caption = Main.Caption
End Property
Public Property Let Caption(NewValue As String)
Main.Caption = NewValue
End Property
Private Sub Class_Initialize()
Main.Show
End Sub
Private Sub Class_Terminate()
Unload Main
End Sub
but it still give me the No creatable public component detected
i changed all the project propertys to what you set them to in your app but still not working
Originally posted by Ultimasnake but it still give me the No creatable public component detected
i changed all the project propertys to what you set them to in your app but still not working
The activeX exe has to have a Public Class (Multiuse, GlobalMultiUse, ...) make sure the class instancing is set to something that is public. Note: If you transfered the classes into the app before switching it to an activeX exe then VB probably changed the instancing of them since normal exes don't ahve public createable classes.
aha think i am starting to get it . but while compiling the example dll you gave me i cant compile it (error see above)
Do you mind writing a dll that works on my program? so i can see it more clearly? it only has to change the FRMmain.caption on load of the dll not with any fancy windows and textboxes :S...
because i still dont really get it how to work from a dll and you added some options in it that make it wierd for me to see if i only want to try a single thing :S
When working with objects you have to Set them to either an existing instance or a new instance you can't just declare them. I assume that the form is called from the class, correct? If so then you should pass the instance calling it to the form like this:
VB Code:
'this would be in the class where the form is called
If you want to expose the whole form you could do that, although then they may change things you don't want changed or that conflict with other plugins or your app. Well you can't expose the form as the type form in COM (because it is a VB only object) you can expose it as the generic object type and it will be the form. Like this:
VB Code:
'in the app in the class plugapp
Public Property Get MainForm() As Object
Set MainForm = frmmain
End Property
'then in the plugin they could do something like this
Hmm well I thought it'd be just a matter of switching the MyPlug variable to an array of objects but I had some problems with that. The problem is that I wrote this code a while ago and can't remember how I did it before. Now the good news, this has peeked my curiosity and so I'm working on it.
Haha thanks allot. well i thought it was a matter of adding an array to it too. But when i added and array it couldn't be a public object anymore hope you find out how to do it in the mean time i will mess around with exposing certain objects
Actually I did and it was just switching it to an array. The trouble I had when I tried yesterday was realted to references. So here is the story if don't need the plugins to gets events raised from the app then life is easy and references aren't a big deal, BUT if you do then all of the normal COM rules apply and anything realted to binary compatibility. What I mean in order for the events to work they must have a valid reference to the PluginApp so if any compatibilty problems occur you have to recompile the plugins. Again this is strictly related to the events. If they are not needed then you can use CreateObject and not worry about that.
Also was a side note VB has a bug regarding certain binary compatibility usages with ActiveX exes which basically means it can't overwrite the activeX exe that it is checking for binary compatibility so you have to keep a copy of your exe in another folder and set the binary compatibility to check that one.
Anyway here are the changes I made, actually on second thought I'll post the project and you can see the changes. The changes are in the 'General Declarations', 'GetNewIndex', 'LoadNewPlug', 'HasBounds', 'Form_Unload' methods.
it seems to work in your app... but i have 1 problem though you use :
VB Code:
Private MyPlugs() As Object
But i must use the My plugs object as a Public module for usage by diffrent forms (the place where i create the MYPLUGS object is in the pluginmanger form and not in the main form where it must be controlled how can i solve that? :S
here is also a beta version of ultima mini player 3 and a simple skin plugin for it (this is where i need all the info for)
Hey does this app use the mci apis to play the files? Because all my music is on a networked path and mci apis don't like network paths. So I didn't have anything to play and I tried the plugin bit but it gave an object error (actually it was when i clicked the 'none installed' menuitem.
Ended up copying some files from the network and playing them but no plugins show up in the plugin manager.
Yes i do play through mci because playing through the WMP adds a extra 2 mb or something for 1 freaking dll. But you must first enable the plugin through PLUGIN>PLUGIN MANAGER . click on the dll on the left side and click ACTIVATE > it will then be in the right list and it will be in the menu as Skin plugin
oh w8 sorry about that . you have to make a directory in the directory where you placed UMP3.exe the directory has to be called PLUGINS in that directory you will have to put the plugin.
err question how to unload a plugin? cant seem to get that one right. i tried unload myplug(index here) or do i have to unload it from the plugin itself
I am playing with your code, and I was wondering if you knew of a way where I could store a MDI Child inside the DLL, and in the MDI Form, load that Child?
I'm having no luck at all with getting it to work.
Unfortunately you can't do that with VB6 (Well, you can come close, but its a royal pain). But search around in here, I believe I posted an explanation on how to do nearly the same thing with usercontrols and mdichild forms.
If you can't find it I'll post it again.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.