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

Run function as soon as .dll loads

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
arcticad
3239 Views, 5 Replies

Run function as soon as .dll loads

Is there a way to run some code as soon as a .dll file is loaded without having to using lisp (command "Function_Name")?

 

Thank You.

---------------------------



(defun botsbuildbots() (botsbuildbots))
5 REPLIES 5
Message 2 of 6
Keith.Brown
in reply to: arcticad

I am a beginning dotnet autocad programmer and use visual basic but I use this to run code when my dll is loaded.  I just grabbed it from the autodesk visual studio wizard.

 

        Implements IExtensionApplication

        Public Sub Initialize() Implements IExtensionApplication.Initialize
            ' Add one time initialization here
            ' One common scenario is to setup a callback function here that 
            ' unmanaged code can call. 
            ' To do this:
            ' 1. Export a function from unmanaged code that takes a function
            '    pointer and stores the passed in value in a global variable.
            ' 2. Call this exported function in this function passing delegate.
            ' 3. When unmanaged code needs the services of this managed module
            '    you simply call acrxLoadApp() and by the time acrxLoadApp 
            '    returns  global function pointer is initialized to point to
            '    the C# delegate.
            ' For more info see: 
            ' http:'msdn2.microsoft.com/en-US/library/5zwkzwf4(VS.80).aspx
            ' http:'msdn2.microsoft.com/en-us/library/44ey4b32(VS.80).aspx
            ' http:'msdn2.microsoft.com/en-US/library/7esfatk4.aspx
            ' as well as some of the existing AutoCAD managed apps.

            ' Initialize your plug-in application here
            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

            ed.WriteMessage("Plugin Loaded successfully...")

        End Sub

        Public Sub Terminate() Implements IExtensionApplication.Terminate
            ' Do plug-in application clean up here
        End Sub

 

 

Message 3 of 6
arcticad
in reply to: Keith.Brown

Awesome, Works great.

Thank You.

---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 4 of 6
chiefbraincloud
in reply to: arcticad

I would have made the same suggestion, but with one caveat.  You need to be careful exactly what you try to do in the initialize routine, as AutoCAD my not be ready for certain things at that time, especially if you are demand loading on AutoCAD startup.

Dave O.                                                                  Sig-Logos32.png
Message 5 of 6
GrzesiekGP
in reply to: arcticad

Hello,

 

Hope someone can help me.

I want to check the license key (from user settings) in Initialize function, but when I set true/false for the global variable in this method, in commands I'm always getting false value. Why?

 

        private bool isLicensed;

        public bool Licensed
        {
            get { return isLicensed; }
            set { isLicensed = value; }
        }

void IExtensionApplication.Initialize()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("Sprawdzanie licencji ... ");
            if (licenseKey == userKey)
            {
                Licensed = true;
            }
            else
            {
                GPLicense gpl = new GPLicense();
                gpl.Show();
                Licensed = gpl.isValidate;
            }
        }

 private bool CheckLicense()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            if (!Licensed)
            {
                ed.WriteMessage("Brak licencji!");
                GPLicense gpl = new GPLicense();
                gpl.Show();
                Licensed = gpl.isValidate;
                return Licensed;
            }
            else
                return true;
        }

        [CommandMethod("GC")]
        public void CleanLayer()
        {
            if (!CheckLicense())
                return;
            GC.CleanLayer();
        }

 

Message 6 of 6

Your command method and the properties of your class are instance members.

 

AutoCAD will create a seperate instance of your class for each document you use your command in.

 

Unless your data is document-specific, you should not be using non-static command methods or instance properties, you should either store that data in a separate class for which there is only one instance, without any non-static command methods (e.g., a singleton), or you should make everything static (the command methods and the properties they access).

 

 

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