Back in the beginning . .
when AutoDesk first provided access to .NET API via wrappings to ObjectARX in AutoCAD 2005 the API wasn't complete (surprised ? )
A lot of functionality had to be accessed using the [DllImport( . . . )} attribute to
define local Methods.
Something like :
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
static internal extern int acedAlert(string prompt);
public static void alert(string msg)
{
try
{
acedAlert(msg);
}
catch
{
throw;
}
}
Then we could generate an alert box in AutoCAD,
alert("Hello World ! and we're happy.");
Fast forward almost 20 years, and we use :
public static void
ShowAlertDialog(string message);
Declaring Type: Autodesk.AutoCAD.ApplicationServices.Core.
Application Assembly: accoremgd, Version=25.0.0.0
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
//----
AcadApp.ShowAlertDialog("Wheeeeeee ....");
To this day the DllImport attribute needs to be called on to import functionality that AutoDesk hasn't yet wrapped.
But, We're still seeing code samples that are using DllImport that doesn't need to because the fuunctionality HAS been included in the API Assemblies.
As we migrate code to .NET8.0 C#12 for ac2025 this may be a good time to refactor code that uses DllImport un-necessarily.
Perhaps we could use this thread for samples we can think of, or find, that could be refactored.
Provide a sample of the Attribute statement and the Library Method we can use instead.
Happy coding,
Regards,
Kerry
I'd like to thank Mark Thomas who, 19 years ago, had the forsight to provide us with a .NET sub-forum to play in, and a second home to share with people who became friends, unsighted.