Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:24:55+00:00 2026-06-05T06:24:55+00:00

I’ve re-created the _DAcadApplicationEvents interface from an AutoCAD interop .dll using .NET Reflector, and

  • 0

I’ve re-created the _DAcadApplicationEvents interface from an AutoCAD interop .dll using .NET Reflector, and have my code working for AutoCAD 2010. The problem is that I need this to be compatible with AutoCAD 2006 all the way up to 2012 and forward. I am running .NET 4.0, and am therefore using Embed Interop Type set to true to make sure my Application object resolves properly to runtime without needing reflection invoke methods, but I can’t seem to find a way to get the event interface working without hard-coding in the GUID (which is assembly specific).


Here is the custom interface I created from the original AutoDesk.AutoCAD.Interop.dll:

    <ComImport(), Guid("1F893620-C96D-4361-BBAF-A61D4144B7F8"), TypeLibType(CShort(&H1010))>
    Public Interface _DAcadApplicationEventsClone
        <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime), DispId(1)>
        Sub SysVarChanged(<[In](), MarshalAs(UnmanagedType.BStr)> ByVal SysvarName As String, <[In](),
                          MarshalAs(UnmanagedType.Struct)> ByVal newVal As Object)

        <MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime), DispId(8)>
        Sub BeginQuit(<[In](), Out()> ByRef Cancel As Boolean)
    End Interface

The Application object gets created in this manner:

Public Application As Object

Application = Marshal.GetActiveObject("AutoCAD.Application")

Next I am connecting to the cloned interface using IConnectionPoint:

Dim acGUID As New Guid(GetInterfaceGUID())

Dim acConnectionPoint As ComTypes.IConnectionPoint = Nothing
TryCast(Application, ComTypes.IConnectionPointContainer).FindConnectionPoint(acGUID, acConnectionPoint)

Dim acSinkCookie As Integer
acConnectionPoint.Advise(Me, acSinkCookie)

As you can see, I’m running a function called ‘GetInterfaceGUID’ to dynamically search for the right GUID depending on what version of AutoCAD is installed on the system. However, if the GUID returned doesn’t match the hard-coded GUID on the interface, it won’t work anyway. I’ve tried different methods of reflection to work with a System._ComObject, and this is the only method that I’ve gotten to even come close. I feel like I’m fairly close to succeeding, and would appreciate any input at this point. Thanks in advance.

-Locke

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:24:57+00:00Added an answer on June 5, 2026 at 6:24 am

    As you found, the AutoCAD COM Interop is version and even bitness (32bit/64bit) dependant. Why not use the AutoCAD .NET Application Events to get rid of these trouble as follows?

    using System;
    using System.Text;
    using System.Linq;
    using System.Xml;
    using System.Reflection;
    using System.ComponentModel;
    using System.Collections;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Media.Imaging;
    using System.Windows.Forms;
    
    using System.IO;
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.Runtime;
    using Autodesk.AutoCAD.EditorInput;
    
    using Autodesk.AutoCAD.Geometry;
    using Autodesk.AutoCAD.Windows;
    
    using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
    using AcadDocument = Autodesk.AutoCAD.ApplicationServices.Document;
    using AcadWindows = Autodesk.AutoCAD.Windows;
    
    namespace AcadNetAddinByVS2010
    {
        public class AppEvents1
        {
            bool mSuppressMsgOutput = false;
    
            void OptionalMessageOutput(EventArgs obj, string eventName)
            {
                if (!mSuppressMsgOutput)
                {
                    string msg = string.Format("Info about the {0} event:{1}", eventName, Environment.NewLine);
    
                    PropertyInfo[] piArr = obj.GetType().GetProperties();
                    foreach (PropertyInfo pi in piArr)
                    {
                        string attValue = pi.GetValue(obj, null).ToString();
                        msg += string.Format("\t{0}: {1}{2}", pi.Name, attValue, Environment.NewLine);
                    }
    
                    MessageBox.Show(msg, "Event: " + eventName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    System.Diagnostics.Debug.Write(msg);
                }
            }
    
            public void Register()
            {
                AcadApplication.SystemVariableChanging += AppEvent_SystemVariableChanging_Handler;
                AcadApplication.SystemVariableChanged += AppEvent_SystemVariableChanged_Handler;
                AcadApplication.QuitWillStart += AppEvent_QuitWillStart_Handler;
                AcadApplication.QuitAborted += AppEvent_QuitAborted_Handler;
                AcadApplication.PreTranslateMessage += AppEvent_PreTranslateMessage_Handler;
                AcadApplication.LeaveModal += AppEvent_LeaveModal_Handler;
                AcadApplication.Idle += AppEvent_Idle_Handler;
                AcadApplication.EnterModal += AppEvent_EnterModal_Handler;
                AcadApplication.DisplayingOptionDialog += AppEvent_DisplayingOptionDialog_Handler;
                AcadApplication.DisplayingDraftingSettingsDialog += AppEvent_DisplayingDraftingSettingsDialog_Handler;
                AcadApplication.DisplayingCustomizeDialog += AppEvent_DisplayingCustomizeDialog_Handler;
                AcadApplication.BeginQuit += AppEvent_BeginQuit_Handler;
    
            }
    
            public void UnRegister()
            {
                AcadApplication.SystemVariableChanging -= AppEvent_SystemVariableChanging_Handler;
                AcadApplication.SystemVariableChanged -= AppEvent_SystemVariableChanged_Handler;
                AcadApplication.QuitWillStart -= AppEvent_QuitWillStart_Handler;
                AcadApplication.QuitAborted -= AppEvent_QuitAborted_Handler;
                AcadApplication.PreTranslateMessage -= AppEvent_PreTranslateMessage_Handler;
                AcadApplication.LeaveModal -= AppEvent_LeaveModal_Handler;
                AcadApplication.Idle -= AppEvent_Idle_Handler;
                AcadApplication.EnterModal -= AppEvent_EnterModal_Handler;
                AcadApplication.DisplayingOptionDialog -= AppEvent_DisplayingOptionDialog_Handler;
                AcadApplication.DisplayingDraftingSettingsDialog -= AppEvent_DisplayingDraftingSettingsDialog_Handler;
                AcadApplication.DisplayingCustomizeDialog -= AppEvent_DisplayingCustomizeDialog_Handler;
                AcadApplication.BeginQuit -= AppEvent_BeginQuit_Handler;
    
            }
    
            public void AppEvent_BeginQuit_Handler(object sender, EventArgs e)
            {
                OptionalMessageOutput(e, "BeginQuit");
    
            }
    
            public void AppEvent_DisplayingCustomizeDialog_Handler(object sender, TabbedDialogEventArgs e)
            {
                OptionalMessageOutput(e, "DisplayingCustomizeDialog");
    
            }
    
            public void AppEvent_DisplayingDraftingSettingsDialog_Handler(object sender, TabbedDialogEventArgs e)
            {
                OptionalMessageOutput(e, "DisplayingDraftingSettingsDialog");
    
            }
    
            public void AppEvent_DisplayingOptionDialog_Handler(object sender, TabbedDialogEventArgs e)
            {
                OptionalMessageOutput(e, "DisplayingOptionDialog");
    
            }
    
            public void AppEvent_EnterModal_Handler(object sender, EventArgs e)
            {
                OptionalMessageOutput(e, "EnterModal");
    
            }
    
            public void AppEvent_Idle_Handler(object sender, EventArgs e)
            {
                OptionalMessageOutput(e, "Idle");
    
            }
    
            public void AppEvent_LeaveModal_Handler(object sender, EventArgs e)
            {
                OptionalMessageOutput(e, "LeaveModal");
    
            }
    
            public void AppEvent_PreTranslateMessage_Handler(object sender, PreTranslateMessageEventArgs e)
            {
                OptionalMessageOutput(e, "PreTranslateMessage");
    
            }
    
            public void AppEvent_QuitAborted_Handler(object sender, EventArgs e)
            {
                OptionalMessageOutput(e, "QuitAborted");
    
            }
    
            public void AppEvent_QuitWillStart_Handler(object sender, EventArgs e)
            {
                OptionalMessageOutput(e, "QuitWillStart");
    
            }
    
            public void AppEvent_SystemVariableChanged_Handler(object sender, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
            {
                OptionalMessageOutput(e, "SystemVariableChanged");
    
            }
    
            public void AppEvent_SystemVariableChanging_Handler(object sender, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangingEventArgs e)
            {
                OptionalMessageOutput(e, "SystemVariableChanging");
    
            }
    
        }
    }
    

    Here is the event registration code in the chosen IExtensionApplication implementation by the way:

    #region Namespaces
    
    using System;
    using System.Text;
    using System.Linq;
    using System.Xml;
    using System.Reflection;
    using System.ComponentModel;
    using System.Collections;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Media.Imaging;
    using System.Windows.Forms;
    using System.Drawing;
    using System.IO;
    
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.Runtime;
    using Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.Geometry;
    using Autodesk.AutoCAD.Windows;
    
    using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
    using AcadDocument = Autodesk.AutoCAD.ApplicationServices.Document;
    using AcadWindows = Autodesk.AutoCAD.Windows;
    
    #endregion
    
    namespace AcadNetAddinByVS2010
    {
        public class ExtApp : IExtensionApplication
        {
            #region IExtensionApplication Members
    
            public void Initialize()
            {
                //TODO: add code to run when the ExtApp initializes. Here are a few examples:
                //          Checking some host information like build #, a patch or a particular Arx/Dbx/Dll;
                //          Creating/Opening some files to use in the whole life of the assembly, e.g. logs;
                //          Adding some ribbon tabs, panels, and/or buttons, when necessary;
                //          Loading some dependents explicitly which are not taken care of automatically;
                //          Subscribing to some events which are important for the whole session;
                //          Etc.
    
                mAppEvents1.Register();
            }
    
            public void Terminate()
            {
                //TODO: add code to clean up things when the ExtApp terminates. For example:
                //          Closing the log files;
                //          Deleting the custom ribbon tabs/panels/buttons;
                //          Unloading those dependents;
                //          Un-subscribing to those events;
                //          Etc.
    
                mAppEvents1.UnRegister();
            }
    
            #endregion
    
            AppEvents1 mAppEvents1 = new AppEvents1();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.