Results 1 to 9 of 9

Thread: [RESOLVED] DCOM .. This has me baffled.

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Location
    Manchester, UK
    Posts
    11

    Smile [RESOLVED] DCOM .. This has me baffled.

    Hi World!,

    I'm trying to learn more about DCOM and i've come up with something i'm stuck on.

    So far I have a server application (actx exe) that consists of 1 class and 1 form, the client creates a new instance of the class and uses a method to pass a string which the server then writes to the harddisk.. the class then adds this to a listbox on the server's form (just for monitoring).. thats great.. so all my clients pass strings to the server and the server gets updated by all the clients..

    BUT.. I now want my server to somehow let all the other clients know there has been a change and update all clients that are attached.. I want to (firstly) do this by having a button on my server form which triggers it

    help please.. I have only been using this DCOM stuff for a couple of days and my heads spinning.. no one replied to my last question :-( please reply to this one ... please!!!
    Last edited by anx992; Oct 28th, 2002 at 11:35 AM.

  2. #2
    Lively Member
    Join Date
    Aug 2002
    Posts
    126
    it is very simple.
    raise event.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Location
    Manchester, UK
    Posts
    11

    Thumbs down wrong end of wrong stick

    no no .. you can't raise the event if you didn't create the instance of the class..

    All clients create an instance of a class .. theres only ever 1 form and all clients can access it .. how do you talk from the form to the client classes?

    ACTIVEX EXE (Want actxform to be able to talk to client class instance)
    ----Form
    ----Class

    Client 1
    ----Class Instance
    Client 2
    ----Class Instance
    Client 3
    ----Class Instance
    Last edited by anx992; Oct 28th, 2002 at 05:23 AM.

  4. #4
    Lively Member
    Join Date
    Aug 2002
    Posts
    126
    i'm sorry, i didn't notice about the form class.
    (i'm sorry, my english is not very well)

    i think it's impossible due to the nature of VB.
    ActiveX EXE creates STA (Single Thread Apartment) for each client (it is not precisely but depend on project configuration).
    it also create a STA for the form.
    each variable that declare in the class (or even in a module) reside in that STA. it means that even if u put global variables in a module, VB create every one them for each STA (class), and it means that u can't share data between these clients instances.
    so, basically, if u could send data between those STA's u wouldn't have a problem to raise an event.

    u do have a solution inside the COM+ era, but u should move your application to DLL COM type.
    COM+ even gives u a new type of events, it called LCE (Loosely Coupled Event).
    in LCE in contrast with standard events, the clients don't have to be bound to the server.
    it works in a publisher, subscribers manner.
    u can read more about COM+ events at:
    http://www.msdn.microsoft.com/librar...lus_events.asp

    i hope this will help u.

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Location
    Manchester, UK
    Posts
    11

    Cool sorted man!

    Thanks for the input Deja but I managed to get it sorted..

    You have to create a class that creates one instance of the main class in a public place (ie module) you then pass the instance of this class to the clients through a method.. the result is all clients use the same instance and they can interact! .. quite kewl the way it works..

    Can be a bit confusing, if anyone needs help with this one send me a message/email whatever and i'll provide a really simple application.

    still stuck with me previous question about property enumerations though :-) help!
    Last edited by anx992; Oct 28th, 2002 at 11:33 AM.

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    http://www.edneeis.com/samples.htm

    Check out the sharing with callbacks example. There used to be some discussion on this but the posts may have got knocked out after the crash.

    All the classes would have to point to the same instance of the form and you'd have to use callbacks instead of events. The same instance of the form can be shared from a module and as long as the ActiveX Exe is using a Thread Pool of 1.

    I believe this is covered in part of the MSDN coffee example (can't remember which one any more).

  7. #7
    Lively Member
    Join Date
    Aug 2002
    Posts
    126
    by finding a solution to the problem doesn't mean that it will be a good one.
    from your answer i figured out the following:

    u launch an EXE process.
    that process create an instance of class A and that instance create another instance of class B.
    those two instances reside in the same STA.
    now, each client (assuming that u configure the EXE to have thread per object) creates in new STA.
    the client inovke a method, and he get a pointer to class B.

    your solution looks to me a little bit circumvention:

    1. u must launch the EXE to create the main class (B), and it means that the EXE is always running and consuming resources.

    2. each client must invoke a special method to achieve the pointer to the main object. this is some kinky way and not very clean. the client has to do very much to get that object.

    3. each client get a proxy to the main object and not a direct pointer to it. this stem from the fact that all the objects in VB can only live in STA and can be accessed only from the apartment who create that object. it means that each client can block the other clients in case of executing long operation on the main object. this can lead to deadlocks and even to application crash.
    it also add overhead to every call from the clients to the object due to thread switching, etc.
    if your object have a mix of operations, some long and some short, clients that r waiting for the short ones can be very frustrated if only one client blocking them by a very long op. the performance could be very better if each of them had it's own copy of the object.

    it is also unnecessary to declare the main class in a module, but just to place it in the class who create it (class A).

    in your case it is even better to configure the EXE to have thread pool of only one object, so VB will create all the client in the same STA as the main object, by that you saving the proxy/stub thread switching, but the blocking problem still remain.

    microsoft did a very much work for solving this kind of programming problem like you have. and for that reason they made COM+. i think u should be very look at it, u will find much better straightforward programming under that environment.
    it gives u a lot of services that u could find very useful for your problems.

    read more about COM apartments and COM+:
    http://codeguru.earthweb.com/activex...artments1.html

    http://www.msdn.microsoft.com/librar...asp?frame=true

    (and again, sorry for my english...)

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Location
    Manchester, UK
    Posts
    11

    Lightbulb response

    Hi Deja,

    Thanks for your extra input.

    I'm going to look at COM+ like you say and try and find a more ??.. professional way of coding this application. I've not had any problem with one client blocking another yet but I can see from what you say that for long operations it will happen eventually.

    I know the difference between COM and DCOM.. what is COM+ ?

  9. #9
    Lively Member
    Join Date
    Aug 2002
    Posts
    126
    COM+ is a runtime environment for COM objects.
    COM+ intended for the middle tier bussines logic in distributed applications.
    it gives your objects a bunch of services like Distributed Transactions, Events (like i mentioned before), Object Pooling, JIT Activation, Queued Components (that ride on MSMQ) and more.
    basically, u create COM+ application and register your COM objects under it.
    COM+ holding a more detailed meta data about your objects then the standard registery.
    when clients create objects that belong to COM+ application, COM+ take care for activating those objects and holding them as long as it takes in memory, and also release them properly in the right moment.
    COM+ launches 10 instances of single object per processor.
    apartments in COM+ is a little bit different from ActiveX EXE, and it takes a good understanding (in COM+ there is a new apartment called Neutral Apartment).
    u will find a lot of stuff concerning to COM+ in MSDN and in other sites.

    i hope it will help you.

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