Search code examples
vb.netcom-interopautocad

COM Errors Visual Studio 2010


Recently I've been working on an external .exe to communicate with AutoCAD. Since it was an outside .EXE I had to work with the COM to get what I wanted. (Else I could've used the .NET API which is (in my opinion) much better).

In any case, I keep getting COM Interop errors (Call was rejected by Callee) and I'm having a lot of trouble dealing with it. I could use timers but sometimes it will over wait, or under wait for a particular situation. Also, this isn't the best solution if I have to use a slower computer.


Solution

  • Microsoft's solution:

    1. Add the following class to your application.
    2. Add a reference to "Microsoft Development Environment 8.0." This adds references to EnvDTE and EnvDTE80 to your solution.

      Add a reference to System.Windows.Forms.

    3. In the code, create an instance of EnvDTE80, as outlined in the following example.
    4. Call Message.Register to handle thread errors.
    5. Call your automation code as usual.
    6. When your automation code is finished, call Message.Revoke to remove the thread error handlers.

    http://msdn.microsoft.com/en-us/library/vstudio/ms228772(v=vs.100).aspx

    Importing

    In order to use the error management code (once the class is added) we will need to add an import such as:

    Imports WindowsApplication1.ConsoleApplication2