.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CoInitialize call from add-ons

6 REPLIES 6
Reply
Message 1 of 7
aknigin
355 Views, 6 Replies

CoInitialize call from add-ons

Hello,

 

We develope a .NET plugin module for AutoCAD which calls some unmanaged code from itself, using COM. In this unmanaged code somewhere we create a thread and call CoInitialize inside of this thread (and, of course, CoUninitialize in pair). When AutoCAD is closed it crashes. If we comment out the CoInitialize calls, then AutoCAD ends successfully. Maybe this problem is not AutoCAD-specific one, but for us this is the first time it happened. So, what is possibly wrong there?

6 REPLIES 6
Message 2 of 7
StormyC
in reply to: aknigin

Just curios, what's the crash error?

Message 3 of 7
Marat.Mirgaleev
in reply to: aknigin

Hi,

 

   Please, ensure you are not accessing the AutoCAD database from the new thread. It is allowed only from the AutoCAD thread itself.

 

Cheers,



Marat Mirgaleev
Developer Technical Services
Autodesk Developer Network
Message 4 of 7
aknigin
in reply to: StormyC

Nothing interesting, something like this: "Unhandled exception at 0x21ed45c8 in acad.exe: 0xC0000005: Access violation reading location 0x21ed45c8."

Message 5 of 7
aknigin
in reply to: Marat.Mirgaleev

No, all database operations are handled in the main thread. Generally we just load the plugin, create the thread and after AutoCAD closing - we get the crash.

Message 6 of 7
StormyC
in reply to: aknigin

How are you implementing the original call to the unmanaged code - using the Implements IExtensionApplication so you can ensure the cleanup is done in the terminate sub?

Just thinking that maybe its not been stopped in time for acad to properly shut down and because your operating in another thread when you call the coinit' that thread isn't killed in time to allow acad to shutdown.

Also there is this to note from MSDN;

Because there is no way to control the order in which in-process servers are loaded or unloaded, do not call CoInitialize, CoInitializeEx, or CoUninitialize from the DllMain function.

Im still fairly new to COM & .NET so these are just areas where I would look if were in your shoes.  Not having the code makes it hard to debug. Smiley Wink

Message 7 of 7
aknigin
in reply to: StormyC

Yes, we implement the IExtensionApplication interface and clean the things in Terminate. The thread ends successfully, as far as I understand.

It is not a big deal to comment out these CoInit calls, but I just want to understand what is the reason of the crash.

Having source code here makes no much sence, because it is quite complicated, I just try to describe the problem shortly 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost