Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC and COM, and Access violation in CoUninitialize

MFC and COM, and Access violation in CoUninitialize

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++comdebugging
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sagmam
    wrote on last edited by
    #1

    Hi everyone, I wasn't sure if this is a COM issue or MFC issue, so I also posted this question in the COM message board... I have an MFC app (with a CWinApp-derived object) that uses COM objects (Crystal Reports). The COM library is imported into my project via the #import directive. I'm using VStudio 6.0 sp5. I've created a global object called _com_init: struct ComInit { ComInit() { ::CoInitialize(NULL); } ~ComInit() { ::CoUninitialize(); } } _com_init_; This way, I guarantee that COM will initialize before the _main() and terminate after the _main(). When my program reaches ~ComInit() and calls ::CoUninitialize(), I see the following message in my Debug Output Window: First-chance exception in MyApp.exe (OLE32.DLL): 0xC0000005: Access Violation. Any ideas? I've looked up other CoUninitialize threads in these forums, but couldn't figure out something that would solve my problem... Thanks. /=/=/=/= Deus /=/=/=/=

    A 1 Reply Last reply
    0
    • S sagmam

      Hi everyone, I wasn't sure if this is a COM issue or MFC issue, so I also posted this question in the COM message board... I have an MFC app (with a CWinApp-derived object) that uses COM objects (Crystal Reports). The COM library is imported into my project via the #import directive. I'm using VStudio 6.0 sp5. I've created a global object called _com_init: struct ComInit { ComInit() { ::CoInitialize(NULL); } ~ComInit() { ::CoUninitialize(); } } _com_init_; This way, I guarantee that COM will initialize before the _main() and terminate after the _main(). When my program reaches ~ComInit() and calls ::CoUninitialize(), I see the following message in my Debug Output Window: First-chance exception in MyApp.exe (OLE32.DLL): 0xC0000005: Access Violation. Any ideas? I've looked up other CoUninitialize threads in these forums, but couldn't figure out something that would solve my problem... Thanks. /=/=/=/= Deus /=/=/=/=

      A Offline
      A Offline
      Antti Keskinen
      wrote on last edited by
      #2

      The most important aspect of using COM with MFC is to initialize and uninitialize COM correctly. Instead of using a global object, I suggest that you put ::CoInitialize(NULL) in the start of your CWinApp-derived application's 'InitInstance' and ::CoUninitialize() o the end of the same application's 'ExitInstance' (Before return call). This way, the initialization and uninitialization are handled smoothly. As for the actual problem, I have just about no idea of where it lies. I suggest using the above methodology to utilize COM server. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

      S 1 Reply Last reply
      0
      • A Antti Keskinen

        The most important aspect of using COM with MFC is to initialize and uninitialize COM correctly. Instead of using a global object, I suggest that you put ::CoInitialize(NULL) in the start of your CWinApp-derived application's 'InitInstance' and ::CoUninitialize() o the end of the same application's 'ExitInstance' (Before return call). This way, the initialization and uninitialization are handled smoothly. As for the actual problem, I have just about no idea of where it lies. I suggest using the above methodology to utilize COM server. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

        S Offline
        S Offline
        sagmam
        wrote on last edited by
        #3

        I already tried that. It was a lot worse when I did that. The result was about a zillion "Access Violation" messages instead of just one. I think there was also a "Stack overflow" message somewhere among them... Also, it may have been unclear earlier, but the program doesn't abort with an Access Violation MESSAGE BOX. I only see the message in the debug output window. If I try what you suggested, I also get an Access Violation message box... /=/=/=/= Deus /=/=/=/=

        P 1 Reply Last reply
        0
        • S sagmam

          I already tried that. It was a lot worse when I did that. The result was about a zillion "Access Violation" messages instead of just one. I think there was also a "Stack overflow" message somewhere among them... Also, it may have been unclear earlier, but the program doesn't abort with an Access Violation MESSAGE BOX. I only see the message in the debug output window. If I try what you suggested, I also get an Access Violation message box... /=/=/=/= Deus /=/=/=/=

          P Offline
          P Offline
          Pir8ofTampa
          wrote on last edited by
          #4

          Have you determined that the COM server is indeed initialized? if(::CoInitialize()!=S_OK) MessageBox(_T("COM INIT FAILED"),NULL,MB_ICONERROR); ??

          S 1 Reply Last reply
          0
          • P Pir8ofTampa

            Have you determined that the COM server is indeed initialized? if(::CoInitialize()!=S_OK) MessageBox(_T("COM INIT FAILED"),NULL,MB_ICONERROR); ??

            S Offline
            S Offline
            sagmam
            wrote on last edited by
            #5

            Yes, I have. I get S_OK. /=/=/=/= Deus /=/=/=/=

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups