Page 1 of 2 12 LastLast
Results 1 to 40 of 41

Thread: How to run active x trough other program

  1. #1

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172

    How to run active x trough other program

    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 ...

    thanks in advance
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  3. #3

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    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.
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. Private Sub Class_Initialize()
    2.     'Set gIFace = New PlugManager 'comment this line out
    3.     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:
    1. Public Sub Main()
    2.     'starts the application and shows the form
    3.     If App.StartMode = vbSModeStandalone Then frmMain.Show
    4. 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.

  5. #5

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    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
    Attached Files Attached Files
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I just downloaded your plugintest and am going to check it out in a sec, but I added a lil code to register the dll if it isn't already registered.

    VB Code:
    1. Public Sub LoadNewPlug()
    2.        'here is the sub go down to the following line
    3.        'Set MyPlug = CreateObject(objName)'comment out this line
    4.  
    5.         'replace it with the code below
    6.         On Error Resume Next
    7.         Set MyPlug = CreateObject(objName)
    8.         If Err.Number = 429 Then
    9.             Shell "regsvr32 /s " & cdlg.FileName, vbHide
    10.             Set MyPlug = CreateObject(objName)
    11.         End If
    12.         On Error GoTo 0
    13.         'continue with the rest of the code in the method

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:

    VB Code:
    1. Public Property Get Caption() As String
    2.     'links to the Caption on frmMain
    3.     Caption = frmMain.Caption
    4. End Property
    5.  
    6. Public Property Let Caption(NewValue As String)
    7.     frmMain.Caption = NewValue
    8. End Property

  8. #8

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    i allready added that but you will have a error here:

    VB Code:
    1. Shell "regsvr32 /s " & cdlg.FileName, vbHide

    if the directory is something like c:\my music\ .. i fixed that in the app
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  9. #9

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    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
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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?

  11. #11

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    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.
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  13. #13
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  14. #14
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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).

  15. #15

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    this is what i have in my plugapp

    VB Code:
    1. Option Explicit
    2.  
    3. 'This object is becomes the global part that is shared among all plugs.
    4. 'Only methods and properties in this class are visible to all the plugs, it serves
    5. 'as somewhat of a go-between for the application in the activeX exe, frmMain in
    6. 'this case.
    7.  
    8. Public Enum AppReturnConstants
    9.     retFailed
    10.     retSuccessful
    11. End Enum
    12.  
    13. Public Property Get Caption() As String
    14.     Caption = Main.Caption
    15. End Property
    16.  
    17. Public Property Let Caption(NewValue As String)
    18.     Main.Caption = NewValue
    19. End Property
    20.  
    21.  
    22.  
    23. Private Sub Class_Initialize()
    24.     Main.Show
    25. End Sub
    26.  
    27. Private Sub Class_Terminate()
    28.     Unload Main
    29. 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
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  16. #16
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  17. #17

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    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
    Attached Files Attached Files
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  18. #18
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I changed some of the instancing of the class in the app part. There is the plugin in the zip to.

  19. #19

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    Aha now i got it m8 thanks if i have any question can i email you?
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  20. #20
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Sure [email protected] I hope it works out or is at least helpful to you.

  21. #21

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    ok it works got one question now :S...

    i have this code in a form:

    VB Code:
    1. Public Plugin As CaptionChanger
    2.  
    3.  
    4. Private Sub Command1_Click()
    5.  Plugin.changeCaption
    6. End Sub
    7.  
    8. Private Sub Command2_Click()
    9.  Plugin.changeText
    10. End Sub

    and this in the captionchanger class

    VB Code:
    1. Public Sub changeCaption()
    2.   gIFace.Application.Caption = "test"
    3. End Sub
    4.  
    5. Public Sub changeText()
    6.      gIFace.Application.test = "a test too"
    7. End Sub

    but it says Object variable or with block variable not set what did i do wrong? :S

    the changing itselfs works if i put them in the inizialize of the class module
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  22. #22
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. 'this would be in the class where the form is called
    2. Load frmNameHere
    3. Set frmNameHere.Plugin=Me
    4. frmNameHere.Show vbModal

  23. #23

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    Great. i am just wondering is there a way to make a something from a form off the program itself change without a function? but just like:

    VB Code:
    1. public function changeform()
    2.   frmmain.caption = "test"
    3. end function

    because if a user wants to create a plugin they dont have to be stuck on the Property's i make right ? :S
    Last edited by Ultimasnake; Aug 5th, 2002 at 01:46 PM.
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  24. #24
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. 'in the app in the class plugapp
    2. Public Property Get MainForm() As Object
    3.     Set MainForm = frmmain
    4. End Property
    5.  
    6. 'then in the plugin they could do something like this
    7. gIFace.Application.MainForm.BackColor = vbBlue

  25. #25

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    thats true but with this knowladge i can in example bind certain thing like a button

    VB Code:
    1. Public Property Get playbutton() As button
    2.     Set MainForm = frmmain.playbutton
    3. End Property
    4.  
    5. 'then in the plugin they could do something like this
    6. gIFace.Application.playbutton.caption = "TEST"

    so declaring all the objects that the user will be able to controll or change will be easier than and better for the user
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  26. #26

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    Ok now i am a bit stuck :S.. how to enable more than 1 plugin at once? i really cant think of a correct way of doing this plz help
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  27. #27
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  28. #28

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    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
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  29. #29

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    Hey did you out how to load more than 1 plugin? :S
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  30. #30
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  31. #31

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    it seems to work in your app... but i have 1 problem though you use :

    VB Code:
    1. 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)
    Attached Files Attached Files
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  32. #32
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You could just expose it by giving the form a public property:
    VB Code:
    1. Public Property Get Plugs(ByVal Index as Integer) as Object
    2.    Set Plugs=MyPlugs(Index)
    3. End Property

  33. #33
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  34. #34

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    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
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  35. #35
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    But there is nothing in the list on the left.

  36. #36

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    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.

    how could i forget
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  37. #37

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    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
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  38. #38
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Its just on object not a control so you just set it to nothing.

    VB Code:
    1. Set MyPlugs(index)=Nothing

  39. #39
    New Member
    Join Date
    Mar 2004
    Posts
    2
    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.

    Thanks in advanced

    Rob

  40. #40
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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.


    Take credit, not responsibility

Page 1 of 2 12 LastLast

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