.NET

Reply
Valued Contributor
StormyC
Posts: 76
Registered: ‎11-19-2010
Message 1 of 10 (188 Views)
Accepted Solution

DllImport for acedGetEnv....

188 Views, 9 Replies
05-03-2014 01:20 AM

Got what I think is an odd situation.  Im trying to access the support paths using the dll import that can be found in a number of sites.  Problem is, the entry point doesnt seem to exist - im sure it worked before.. any help would be appreciated.

 

AutoCAD2014, Win7 64, VSExpress2010, C#

 

acerror.png

*Expert Elite*
Alfred.NESWADBA
Posts: 8,916
Registered: ‎06-29-2007
Message 2 of 10 (181 Views)

Re: DllImport for acedGetEnv....

05-03-2014 02:02 AM in reply to: StormyC

Hi,

 

acedGetEnv is placed in ACCORE.DLL and not in ACAD.EXE (I guess since 2013).

 

BTW: why don't you use the more direct option to get sysvar's:

   Public Shared Function GetSystemVariable(name As String) As Object
      Member von Autodesk.AutoCAD.ApplicationServices.Core.Application

 

- alfred -

 

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
StormyC
Posts: 76
Registered: ‎11-19-2010
Message 3 of 10 (179 Views)

Re: DllImport for acedGetEnv....

05-03-2014 02:14 AM in reply to: Alfred.NESWADBA

Thanks for the reply, but, I dont think the support file search path is a system variable that can be edited that way.

*Expert Elite*
Alfred.NESWADBA
Posts: 8,916
Registered: ‎06-29-2007
Message 4 of 10 (176 Views)

Re: DllImport for acedGetEnv....

05-03-2014 02:16 AM in reply to: StormyC

Hi,

 

for editing:

   Public Shared Sub SetSystemVariable(name As String, value As Object)
      Member von Autodesk.AutoCAD.ApplicationServices.Core.Application

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
StormyC
Posts: 76
Registered: ‎11-19-2010
Message 5 of 10 (173 Views)

Re: DllImport for acedGetEnv....

05-03-2014 02:27 AM in reply to: Alfred.NESWADBA

The system variable is readonly....

*Expert Elite*
Alfred.NESWADBA
Posts: 8,916
Registered: ‎06-29-2007
Message 6 of 10 (165 Views)

Re: DllImport for acedGetEnv....

05-03-2014 02:51 AM in reply to: StormyC

Hi,

 

>> The system variable is readonly....

Which sysvar?

 

And back to start:

>> Problem is, the entry point doesnt seem to exist - im sure it worked before

Have you seen my first sentence in my first post?

      acedGetEnv is placed in ACCORE.DLL and not in ACAD.EXE (I guess since 2013).

 

At least:

Does >>>that thread<<< abotu adding a path to the list of support paths help?

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
_gile
Posts: 2,078
Registered: ‎04-29-2006
Message 7 of 10 (156 Views)

Re: DllImport for acedGetEnv....

05-03-2014 03:06 AM in reply to: Alfred.NESWADBA

Hi,

 

As Alfred said, since AutoCAD 2013, the acad.exe file have been splited into acad.exe and accore.dll.

Try replacing acad.exe with accore.dll in the DllImport arguments.

 

Anyway, to get and/or set support paths, you can use COM to access to AutoCAD preferences.

 

This needs to reference the COM librairies or use the Dynamic type. The inconvenients of the first route are the advantages of the second one and vice versa.

Referencing COM libraries means using static typing with type checking at compile time which is a great help during edition time (intellisense), but COM librairies are verion and processor architecture dependant which may be an inconvenient.

 

Using COM libraries

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Runtime;

namespace AcadPreferencesStaticTyping
{
    public class CommandMethods
    {
        [CommandMethod("Test")]
        public void Test()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            AcadPreferences prefs = (AcadPreferences)Application.Preferences;
            string[] supportPaths = prefs.Files.SupportPath.Split(';');
            foreach (string str in supportPaths)
            {
                ed.WriteMessage("\n{0}", str);
            }
        }
    }
}

 

Using Dynamic type

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace AcadPreferencesDynamicTyping
{
    public class CommandMethods
    {
        [CommandMethod("Test")]
        public void Test()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            dynamic prefs = Application.Preferences;
            string[] supportPaths = prefs.Files.SupportPath.Split(';');
            foreach (string str in supportPaths)
            {
                ed.WriteMessage("\n{0}", str);
            }
        }
    }
}

 

As the codes are very similar, it's quite easy to reference the COM libraries while writing an debugging and, when all works as expected, remove these references and replace the COM types with the 'dynamic' keyword.

Gilles Chanteau
Valued Contributor
StormyC
Posts: 76
Registered: ‎11-19-2010
Message 8 of 10 (151 Views)

Re: DllImport for acedGetEnv....

05-03-2014 03:13 AM in reply to: Alfred.NESWADBA

Which Sysvar:  ACADPREFIX

 

Yes, saw your first sentance but for some reason i didnt think it was the same thing as importing from the .exe

 

Forgive me, Ive just tried it by importing from ACCORE.DLL and that works, for reading & writing.

 

Your other link is to use the interop library, which I wanted to avoid.

 

Many Many thanks for your help!!

 

How did you find that acedGetEnv had moved?

 

Again Thanks!

Valued Contributor
StormyC
Posts: 76
Registered: ‎11-19-2010
Message 9 of 10 (148 Views)

Re: DllImport for acedGetEnv....

05-03-2014 03:18 AM in reply to: _gile

Gilles, many thanks for that reply - I had read about dynamic types but forgotten about them.

 

I may just rewrite it to use those.

 

Thanks both!

*Expert Elite*
Alfred.NESWADBA
Posts: 8,916
Registered: ‎06-29-2007
Message 10 of 10 (146 Views)

Re: DllImport for acedGetEnv....

05-03-2014 03:19 AM in reply to: StormyC

Hi,


>> Forgive me,

You are welcome, no need to appologize, the most important thing is you got it solved and you can continue to work :smileywink:

 

>> How did you find that acedGetEnv had moved?

For Invokes and similar things I use Dependency Walker >>>click<<<.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community