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

Difficulty migrating .NET exe to dll

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
mdshameer
748 Views, 7 Replies

Difficulty migrating .NET exe to dll

Hi,

I have made a .NET exe, that communicates with AutoCAD.

As AutoDesk exchange requires dll, I built the Visual Studio solution with application type Class Library. The output DLL was used in .bundle.

But, although, the command is loaded (in autosuggestions), AutoCAd returns "Unknown Command".

Can anyone help why does this happen?

[Instead of .dll, a .lsp works. So I doubt the problem is with my converting exe to dll. I am not with a formal programming background]

Thanks in advance

MdShameer

 

 

 

7 REPLIES 7
Message 2 of 8

Hi,

 

When you migrate something from EXE to DLL for AutoCAD, you need to make adjustments so AutoCAD will recognize the commands.

 

For instance, all methods that a user can call must have a CommandMethod attribute. This is done with some additional references, not available on EXE: AcMgd, AcDbMgd and AcCoreMgd (this last for 2013+)

 

Not sure how far you are on the migration, let us know...

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 3 of 8
Buzz0m
in reply to: mdshameer

Hi,

I have the same problem... how did you solve this?

- F

Message 4 of 8
mdshameer
in reply to: Buzz0m

I do not exactly recall how I overcame this problem. But, looking back at the VS project files, I think you can check the following: 

  1. Check references and build specifications
  2. I now have a file in my VS project which contains the CommandMethod (as suggested by Augustus in reply to my question) but I don't recall where I got the sample code for CommandMethod from. If you so need I can share the file or its content with you.

Regards

Shameer

Message 5 of 8
Buzz0m
in reply to: mdshameer

Hi @mdshameer,

moments after I posted I figured out I need to do something like that 😃

 

If I understood correctly, you have one .dll file ("startup.dll") which contains the commandmethod. This method references the original ".exe"-code ("program.dll"), which has been built into a .dll-file? So in autocad you pass the command to startup.dll (using the PackageContents.xml) which in turn tells program.dll to run...?

 

In my case I have winform program in c# which works fine by itself. I'd like to publish it in autodesk exchange and need to make it work via AutoCAD. Do you think I'm on the right track or do I need to know something more?

- F

Message 6 of 8
Buzz0m
in reply to: mdshameer

Could you please post the code with the commandmethod. I still haven't figured it out... thanks )(
Message 7 of 8
Buzz0m
in reply to: mdshameer

It's like a goddamn miracle cure when I post on this thread! AGAIN seconds after posting I get the code to work! Thanks for your cosmic positive radiance 😉
Message 8 of 8
Buzz0m
in reply to: Buzz0m

Here's the code that I used (in case somebody else needs an example). My build was for Acad 2017... don't know too much about the namespaces (some or most of the ones listed below might be redundant) but they were referenced when I used the acad template so I left them as they were...

 

using System;
using System.IO;
using System.Reflection;
using System.Diagnostics;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(C2A_startup.MyCommands))]

namespace C2A_startup
{

    public class MyCommands
    {
        [CommandMethod("C2A", CommandFlags.Modal)]
        public void myAppStartup() //This method starts the myApp.exe
        {
            Assembly currentAssem = Assembly.GetExecutingAssembly();
            string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            
            Process myProcess = new Process();
            
            myProcess.StartInfo.FileName = assemblyFolder+ "\\myApp.exe";
            myProcess.Start();  
        }
    }
}

- F

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