Results 1 to 4 of 4

Thread: AxtiveX EXE - Connecting

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Question AxtiveX EXE - Connecting

    I have an ActiveX EXE on a server. How is it possible for all clients application to reference the same instance?

    Basically I want 10-50 clients to use the same AxtiveX EXE which create only ONE connection to a database.

    Is this possible, if so then how?

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Was the exe created in VB? If so this is not simple straight forward, but I wil provide the code. I assume this server is part of your local network.

    First off in order to access a running instance of a class in an activex exe or dll you need the getobject command

    Dim a as object
    set a = GetObject("network location of activex exe","projectname.classname")

    now normally that would let you call the functions of a existing instance like this

    a.functionname

    but here is the problem.
    VB ActiveX projects do not write themselves to what is called the ROT..I forgot what this means unfortunatly.Some kind of temporary registry.

    But there is a API workaround. Just add this code to the class

    Code:
    Option Explicit
    
    Private Type GUIDs
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(0 To 7) As Byte
    End Type
    
    'Declares needed to register object in the ROT
    Private Const ACTIVEOBJECT_STRONG = 0
    Private Const ACTIVEOBJECT_WEAK = 1
    Private Declare Function CLSIDFromProgID Lib "ole32.dll" (ByVal ProgID As Long, rclsid As GUIDs) As Long
    Private Declare Function CoDisconnectObject Lib "ole32.dll" (ByVal pUnk As IUnknown, pvReserved As Long) As Long
    Private Declare Function RegisterActiveObject Lib "oleaut32.dll" (ByVal pUnk As IUnknown, rclsid As GUIDs, ByVal dwFlags As Long, pdwRegister As Long) As Long
    Private Declare Function RevokeActiveObject Lib "oleaut32.dll" (ByVal dwRegister As Long, ByVal pvReserved As Long) As Long
    Dim OLEInstance As Long
    
    
    Private Sub Class_Initialize()
    'This code is responsible for creating the entry in the rot
    
    Dim mGUID As GUIDs
    Dim lp As Long
    OLEInstance = 0
    lp = CLSIDFromProgID(StrPtr("UserModule.clsUserMod"), mGUID)
    If lp = 0 Then
        lp = RegisterActiveObject(Me, mGUID, ACTIVEOBJECT_WEAK, OLEInstance)
    End If
    
    End Sub
    
    Private Sub Class_Terminate()
    'Once we are done with the main program, lets clean up the rot
    'by removing the entry for our ActiveX Server
    
    If OLEInstance <> 0 Then
        RevokeActiveObject OLEInstance, 0
    End If
    
    CoDisconnectObject Me, 0
    
    End Sub
    just change "UserModule.clsUserMod"

    to your activex exe's projectname.classname
    good luck
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Did anyone see that high speed hair cut? faster than muppets in space.

    Errr...

    I am not a big fan of API, purely due to the fact that I don't know it well enough yet. But that will soon change.

    One question. What does the above do?

    I have an AxtiveX EXE on my computer and when I run multiple programs, all different, and they access the EXE they can see all the same Public varibles and their values. Does this mean they are seeing the same "instance", or am I just talking crap and am confusing myself?

    Cheers for your help by the way...

    Oh, one last thing. I create an ActiveX DLL and an ActiveX EXE, both with the same class modules, Office and Offices, where Offices is a collection of Office. When these loaded the data off the server for 600 offices and passed them to my UI the DLL took 2.1s to populate a grid, where as the EXE took 12s. That was with 1 application. Now when I ran 3 applications at the same time my DLL application still only took 2.5s each, where as the EXE took 15s, 30s and 34s respectively.
    These have the same code and properties, just one is DLL and other is EXE.
    I knew EXE's were slower, but I didn't think they were THAT slow...

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    sorry if ti seems complex but that is what you have to do to access a running isnatnce if a VB object.

    otherwise they may see the same functions, but they are of differnet instances.

    For example lets say you have 2 clients conencted to your activex if one of them populates a collection, the second cannot access the data client 1 put into the collection. But using that code I gave you along with GetObject allows you to do that.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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