Zugriff auf AutoCAD 2025 mit COM Interop führt zu einem FehlerC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Zugriff auf AutoCAD 2025 mit COM Interop führt zu einem Fehler

Post by Anonymous »

Ich habe eine Anwendung migriert, die über COM Interop von .NetFramework zu .NET 8 und AutoCAD 2025 zugreift, was .NET 8. AutoCAD 2025 application open, I'm receiving the following error at the line of code indicated:

System.Runtime.InteropServices.COMException: 'Operation unavailable
(0x800401E3 (MK_E_UNAVAILABLE))'

I found some posts Bei diesem Fehler, aber die meisten schienen mit COM mit alter Version von MS Office zu adressieren. Jede Hilfe wird geschätzt. < /P>

Code: Select all

    public bool ConnectToAcad() {

try {
string ACADId = "AutoCAD.Application.25.0";
AcadApplication a = (AcadApplication)MyCOM.getActiveObject(ACADId);

if (_AcadApp != null) {
Marshal.ReleaseComObject(_AcadApp);
_AcadApp = null;
}

_AcadApp = a;
return true;
}
catch (COMException)
{
if (_AcadApp != null)
{
Marshal.ReleaseComObject(_AcadApp);
_AcadApp = null;
}

MessageBox.Show("Unable to connect to AutoCAD.\r\nIf AutoCAD is closed, please reopen it and try again.", "Notice");
return false;
}
}

public class MyCOM
{
[DllImport("oleaut32.dll", PreserveSig = false)]
static extern void GetActiveObject(ref Guid rclsid, IntPtr pvReserved,
[MarshalAs(UnmanagedType.IUnknown)] out Object ppunk
);

[DllImport("ole32.dll")]
static extern int CLSIDFromProgID([MarshalAs(UnmanagedType.LPWStr)] string lpszProgID,
out Guid pclsid
);

public static object getActiveObject(string progId)
{
Guid clsid;
CLSIDFromProgID(progId, out clsid);

object obj;
GetActiveObject(ref clsid, IntPtr.Zero, out obj); //ERROR OCCURS HERE

return obj;
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post