Results 1 to 2 of 2

Thread: CoCreateInstance in COM

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    7

    CoCreateInstance in COM

    Hi all,
    I just had a question in my mind .. regarding
    CoCreateInstance in COM.
    Suppose i have a command button which calls
    CoCreateinstance on a particular Dll each time it is clicked.
    Now suppose i click the button 10 times , then what
    happens. Do i have 10 insances of the Dll in my process or
    a single Dll with 10 reference counts on it .
    - vibin
    Vibin.B.Nair

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    You have 10 instances of the object you've created. You only increase the reference counter when you set one variable equal to an existing object. Such as...
    VB Code:
    1. Dim o As Object, o2 As Object
    2.  
    3.   '** Two separate instances
    4.   Set o = CreateObject("VB.Label")
    5.   Set o2 = CreateObject("VB.Label")
    6.  
    7.   '** One instance, two references
    8.   Set o = CreateObject("VB.Label")
    9.   Set o2 = o

    In the second one, the memory taken up by the created object is not eligible for garbage collection until both variables are set to Nothing, or they fall out of scope.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

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