Results 1 to 10 of 10

Thread: Connecting to an Instance.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    66

    Talking Connecting to an Instance.

    Hi

    Lets say you create an object and it runs in its own process space. It has the ability to provide certain services. Is it at all possible to connect to a running instance of that object. By connecting I mean not creating your own instance of that object but simply connecting to an already runing instance.

    Mustafi *

  2. #2
    jim mcnamara
    Guest
    Yes. Use

    Set myNewObj = GetObject("object name","servername")

    Servername is only required when it is on another node.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    66
    Thanks Jim

    However, GetObject only works if the componant you are trying to connect to wasnt written in VB.

  4. #4
    jim mcnamara
    Guest
    Sorry. That is not correct.

    COM is absolutely not dependant on the source language. COM is purely binary. I can access a COM object written in C++ from any language that supports COM; one written in VB from VB, C++, J++, etc.

    Believe me or not, makes no difference - but consider doing some reading. VB COM from Wrox Press is for VB development and deployment of COM objects. It's aimed completely at VB programmers. It also explains the limitations of GetObject vs. CreateObject. And how COM works.

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Well put Jim. That's the beauty of COM, Seamless...

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    66
    Hi Jim,

    I hope you swallow :-)

    Check it out:
    http://msdn.microsoft.com/library/de...eateobject.asp

    Take special note of:

    "You are trying to use the GetObject function to retrieve a reference to class created with Visual Basic.
    GetObject can't be used to obtain a reference to a class created with Visual Basic."

    If you find any info that says otherwise, please drop me a line!

  7. #7
    New Member
    Join Date
    Oct 2001
    Posts
    3

    Red face About GetObject

    Sorry Jim.

    To be honest I was expecting the same, but we can't use the getobject function. See what the GetObject function says:

    "If an object has registered itself as a single-instance object, only one instance of the object is created, no matter how many times CreateObject is executed. With a single-instance object, GetObject always returns the same instance when called with the zero-length string ("") syntax, and it causes an error if the pathname argument is omitted. You can't use GetObject to obtain a reference to a class created with Visual Basic."
    DaMo

  8. #8
    jim mcnamara
    Guest
    Yes, but that is because VB lets you create single instance objects. It's not because the code was written in VB per se.
    If you create a single instance object in C++ you have the same problem.

    If I read it right, Mustafi created an ActiveX server object. These are usually not single instance objects, because that defeats the purpose of an ActiveX server on a separate node. This would mean a new process for every connection.

    What all this means is:
    If you think you have an instance of an object running somewhere, you normally call GetObject. Why? because it is more efficient. CreateObject makes an all-new instance.
    GetObject will fail in the special circumstance you're talking about.

    I've got COM code all over the place written in VB. Some of it works with GetObject.

    We're talking apples & oranges here. Like I said, it makes no difference if you want to see my point of view or not. Just go learn how it all really works, then tell me I'm full of it. That'll be fine. Meanwhile use New and CreateObject.

    What most programmers want is to get past a problem. Just that.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    66

    Lightbulb

    Hiya Jim

    I agree fully, all I need is a solution to the problemo. So
    if I want a single-instance object and need to use this instance in multiple apps what are my options.

    Much Appreciated.

    Mustafi *

  10. #10
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    Hi Jim,

    I would like to know how you got the GetObject function to work with any of your VB code? I have been researching this for weeks and come up with 1 answer each time; IT AINT POSSIBLE!

    Further investigation showed that this is because the VB objects are not inserted into the Running Object Table. The GetObject function retrieves a reference to the running instance of an object by querying this table. The objects reference can be inserted and removed using these two functions:

    RegisterActiveObject and RevokeActiveObject.

    These are a part of the OLE api and not of the opperating system. I have looked for the VB declarations in MSDN and all over the internet but haven't come up with anything.

    Yes we agree that COM is not language dependent, but its functionality is. This is purely because of the way in which VB lets us CreateObjects. We are not given the opportunity to register the objects in the ROT when using VB. It seems in many instances, VB simplifies a lot of what is needed to create objects and applications (Hence "Basic").

    -----------------------------------------------------------------------
    Looking again through MSDN does however provide an alternative. This would be to use a MultiUse ActiveX .exe. Within this component, there must be a minimum the following:
    A public not creatable class (X)
    A public multiuse class (Y)
    A standard module (Z)

    X is declared as public in Z. This makes it available to the entire component. A number variable(glngRefCount) is also declared as public in Z. This will be the reference counter (ie. How many applications are connected).

    When an application creates the object, the first class to be created will be Y. In the initialization, a check should be placed to check the value of glngRefCount. If the count is 0 then this is the first application to connect, so create X and increment glngRefCount. If not, just increment glngrefcount since X is already created.

    It is important to note at this point that a MultiUse ActiveX .exe component is only created once within a system. It is the classes within this component which have multiple instances. Hence, the value of a public variable within a standard module will be available to all instances of the classes within the component.

    X will therefore be available to all instances of Y that are created. You can then manipulate X through Y from any one of the connected clients.
    ---------------------------------------------------------------------------


    Sharing the CoffeMonitor

    RegisterAvtiveObject in C++

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