Doubt in COM

This is a discussion on Doubt in COM within the Windows Programming forums, part of the Platform Specific Boards category; HELLO, I have a doubt in COM. Addref function adds the number of objects If I call release once ,will ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    6

    Doubt in COM

    HELLO,

    I have a doubt in COM.

    Addref function adds the number of objects
    If I call release once ,will it be safe .

    can anyone tell me abt this concept ?

  2. #2
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    Release must be called for each COM object you construct yourself. So the answer is not if you only call Release once for more than one object.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    6

    in memory......

    Thanks for the information...


    Is there any way to locate in the
    memory where these objects gets added up and released...
    Or any tools that is easy to use for a beginner like me..

  4. #4
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    COM keeps track of it for you internally. Why I don't know. Microsoft's Visual C++ 6.0 and .Net have wizards that help you with COM and ATL to build services and programs.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by velius
    COM keeps track of it for you internally. Why I don't know.
    The reason is that a COM object may be referenced by more than 1 interface.

    IE; The first reference to CMyComObj2 might come from some sort of object factory via IUnknown (the interface that gives the AddRef & Release virtual funcs). You might then use QueryInterface (also from IUnknown) to get the IMyComObj interface (allowing you to use the object's member funcs)...and leter use QueryInterface again to get access to IMyComObj2 to get access to extra more recent facilities avaialable.

    Now you have 3 interfaces, but 1 object. So if I deleted the object before all interfaces were done I would face a nasty crash. So Com's reference counting allows you to free an interface when your done without worrying if the object has been destroyed as a result

  6. #6
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    Thanks for that explanation. I barely know COM. The newer DirectX SDK is driven by COM so I needed to learn something about it. That was something I guess I must have forgoten about.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  7. #7
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    If you are using it for DX, then there's not too much you need to know about......some info on reference counting and using QueryInterface might indeed be useful, knowledge of GUIDS and what they do, and being happy to use interfaces......have that it you shouldnt be too bothered.

    Com can get a little complex when you start creating components yourself.....lot's messing around with the registry, using the IDL (Interface Definition Language), Mutlithreading concerns, Dual Interfaces, Aggregation and object factories........that's where ATL becomes very usfull for Com as it uses wizards, macros & templates to shield you from the bare nastiness of writing a Com component.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubt in pointer.
    By shwetha_siddu in forum C Programming
    Replies: 5
    Last Post: 03-21-2009, 01:28 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 12:49 PM
  3. Replies: 4
    Last Post: 12-10-2006, 06:08 PM
  4. Doubt abt Storage!
    By kalamram in forum C Programming
    Replies: 1
    Last Post: 04-21-2006, 05:30 AM
  5. Greatest C++ Doubt
    By vasanth in forum C++ Programming
    Replies: 15
    Last Post: 02-28-2002, 03:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21