Results 1 to 6 of 6

Thread: Can I limit the no of instances od an dll?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    MA, US
    Posts
    78

    Can I limit the no of instances od an dll?

    Hi,

    I'm interested to know if it possible to limit (or detect) the no of instances of an dll (VB6) that are running or are instantiated.
    I would like to limit the no of instances from inside the dll, (if the no of instances reach a limit all the new tentative of instantiating will do something else (return a busy code...)

    thank you,

    Sorin

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You could create a counter in the class's initialize event and increment it by 1, and decrement it by 1 in the class terminate event.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    MA, US
    Posts
    78

    This will work for different clients?

    Lethal,

    Thank you for answer.
    This solution will work for a different clients? Practicly this dll will be called from a stored procedure on a SQL server, and I want to limit the no of instances that run at an time. I'm not sure if the instances will be able to comunicate if they are not created by the same client.

    Thank you,

    Sorin

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Sure it will work. What you will have to do is create an ActiveX EXE so it will run in a seperate process space as the client(s). Also, put the counter into a standard .bas module and make sure that the class's instancing property is set to multi use so all of the clients share the same instance of the component. Good Luck

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    MA, US
    Posts
    78

    my example does not work

    Lethal,

    I tried your advice and I added an bas module where will be the counter.
    The counter is incremented into the initialization of the class and decremented into the terminate sub.
    The component type was changed to activeX.exe and all the clases are multiuse.
    When I use diferrent clients, each instance generated by the each client report a counter of 1 (It seems that the instances does not share the module.
    I hoped I didn't do any mistake, but my code does not work in the way you said.
    Can you build a very small example for me.

    Thank you,

    Sorin

  6. #6
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Hmm...I just tried it and it worked for me. What I bet happened is that in the project proeperties, the threading options is set to 'Thread per object'. What this does is create a thread for each new object that a client creates. Meaning, each thread gets its own copy of the global data section. Try this, I just notied that you said you wanted to use a dll. So, create a dll, create a public counter in a bas module, and add the same code as I described above. This will allow you to stop the number of instances.
    Last edited by Lethal; Jan 12th, 2002 at 02:32 PM.

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