CoInitialize/CoUninitialize

This is a discussion on CoInitialize/CoUninitialize within the Windows Programming forums, part of the Platform Specific Boards category; Hello everyone, I want to develop an automatic tool or manually using existing tool (e.g. WinDbg) to watch when CoInitialize/CoUninitialize ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    CoInitialize/CoUninitialize

    Hello everyone,


    I want to develop an automatic tool or manually using existing tool (e.g. WinDbg) to watch when CoInitialize/CoUninitialize is called. I suspect CoUninitialize is not called the same times as CoInitialize, and I want to get the call stack.

    Any ideas or reference documents about how to do this?

    (I do not have the full source codes, but I have symbol files. My current ideas is either to add to system level COM Runtime hook to monitor when the two functions are called and get stack trace if possible, or using WinDbg to monitor the two specific function calls -- but I do not know the command in WinDbg. :-) )


    thanks in advance,
    George

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    CoInitialize is called before any COM is used. CoUnitialize is called when using COM is no longer necessary.
    Typically, the first is at the start of the application and the second is at the end.
    So of course they are not called at the same time.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    He means the same number of calls.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    Then obviously yes.
    Else, there's a bug.
    Quote Originally Posted by MSDN
    A thread must call CoUninitialize once for each successful call it has made to CoInitialize or CoInitializeEx, including any call that returns S_FALSE.
    (George2 wrote confusing english, so I misinterpreted due to a missing word.)
    Last edited by Elysia; 06-24-2008 at 09:19 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    This should get you started - msdn: Logger and LogViewer
    The Debugging Tools for Microsoft Windows package includes a pair of tools named Logger and LogViewer. These provide an alternative to standard user-mode debugging. Logger can monitor the actions of a user-mode target application and record all of its API calls. The resulting information can be displayed in the debugger, saved as a text file, or displayed in a powerful interactive format by the LogViewer tool.
    And, maybe something like this would do in debugger: "bu ole32!CoInitialize". I'm just wild guessing.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by Elysia View Post
    Typically, the first is at the start of the application and the second is at the end.
    Start and end of each thread actually.

    I assume simply reviewing the code to try and find mismatches has already been tried?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    Quote Originally Posted by iMalc View Post
    Start and end of each thread actually.
    Ah yes, it's thread dependant, isn't it?
    I've typically only use little COM and in the main thread.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

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