메뉴 닫기

CoInitialize의 기능

C++에서 COM 객체를 사용하기 위해서는 객체를 사용하려는

각 Thread에서 CoInitialize나 CoInitializeEx를 호출해 줘야 합니다.

또한 CoInitialize를 호출하면 COM 객체의 사용이 끝났을 때 반드시 CoUninitialize를 호출해 줘야 합니다.

CoInitialize를 n 번 호출할 경우 CoUninitialize도 n 번 호출이 되어야 한다는 의미 입니다.

CoInitialize가 S_FALSE를 리턴할 경우 S_FALSE를 리턴한 경우를 포함해서 CoUnintialize를 호출해야 합니다.

그런데 문제는 CoInitializeEx의 경우 다음과 같은 경우에 문제가 발생할 수 있습니다.

CoInitializeEx(COINIT_APARTMENTTHREADED)
CoInitializeEx(COINIT_MULTITHREADED)
CoUninitialize()
CoUninitialize()


위와 같이 호출한 경우 두번째 CoInitializeEx(COINIT_MULTITHREADED)를 호출하면

함수는 reference count를 증가시키지 않고 RPC_E_CHANGED_MODE 를 리턴합니다.

이렇게 되면 CoUninitialize의 호출이 더 많이 일어나게 되어 아직 COM 객체를 사용중인데도 불구하고 관련 연결이나 메모리들이 해제되어버리는 사태가 발생합니다.

이 문제를 해결하려면 RPC_E_CHANGED_MODE를 에러로 간주하고 reference count를 유지시키는 방향으로 코드를 작성하는 것이 좋습니다.

혹은 문제가 발생하지 않도록 reference count를 관리할 또다른 방안이 필요합니다

35 Comments

  1. g give

    Having read this I thought it was very informative. I appreciate
    you taking the time and effort to put this short article together.
    I once again find myself personally spending way too much time
    both reading and leaving comments. But so what,
    it was still worthwhile!

  2. http://j.mp/3drY6lE

    Cbd oil that works 2020
    Today, I went to the beachfront with my children. I found a sea shell and gave it to my 4 year
    old daughter and said “You can hear the ocean if you put this to your ear.” She
    placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is entirely off topic but
    I had to tell someone! best rated cbd oil http://j.mp/3drY6lE cbd oil that works 2020
    http://j.mp/3drY6lE

  3. Rudolph Aldrege

    I just want to mention I’m newbie to weblog and definitely loved this blog site. Very likely I’m likely to bookmark your site . You absolutely come with impressive posts. Thank you for sharing your website.

  4. buy cbd

    I just couldn’t depart your site prior to suggesting that I extremely enjoyed the standard information an individual provide for your visitors? Is gonna be back frequently in order to inspect new posts

  5. best hosting

    Do you have a spam issue on this website; I also am a blogger, and I was curious about your situation; we have created some nice methods and we are looking to swap strategies with others,
    please shoot me an e-mail if interested.

  6. cvs cbd oil capsules

    There are some fascinating points in time in this post however I don?t understand if I see every one of them facility to heart. There is some legitimacy yet I will hold opinion till I consider it further. Good write-up, many thanks as well as we want much more! Included in FeedBurner too

  7. he said

    This website is really a walk-through for every one of the info you wanted about this and also didn?t recognize who to ask. Glance right here, and also you?ll definitely uncover it.

  8. Madelyn Bobbs

    An interesting conversation is worth comment. I think that you ought to create a lot more on this subject, it could not be a frowned on subject however usually people are not enough to speak on such subjects. To the next. Cheers

  9. Lorilee Horan

    I uncovered your blog website on google and inspect a few of your very early blog posts. Remain to keep up the excellent operate. I simply added up your RSS feed to my MSN News Viewers. Looking for onward to learning more from you later!?

  10. i was reading this

    I discovered your blog site on google as well as check a few of your very early posts. Continue to maintain the very good run. I simply extra up your RSS feed to my MSN Information Reader. Looking for ahead to reading more from you in the future!?

  11. go right here

    When I initially commented I clicked the -Inform me when brand-new comments are added- checkbox as well as currently each time a comment is added I get four emails with the exact same remark. Exists any way you can remove me from that service? Many thanks!

댓글 남기기

이메일은 공개되지 않습니다.