Running a dll From Another dll

Running a dll From Another dll

mgorecki
Collaborator Collaborator
1,723 Views
10 Replies
Message 1 of 11

Running a dll From Another dll

mgorecki
Collaborator
Collaborator

I have a program that currently uses a sub to create part of a specific drawing.

I have a request to make a standalone program from that sub so users can run just that part of the program.

What is the best way to do this?

I would like the designer to have the ability to just run the standalone, but the original program should be able to run it as well.

I don't want to have it in two places as I don't want to have to update code in two different locations.

 

Thanks

0 Likes
Accepted solutions (1)
1,724 Views
10 Replies
Replies (10)
Message 2 of 11

ActivistInvestor
Mentor
Mentor

You should decouple your sub from the program that contained in and place in a separate assembly/project. Then you can reference it from the program that you removed it from as well as any other program that you write and want to use it with.

0 Likes
Message 3 of 11

mgorecki
Collaborator
Collaborator

Hi, yes I was hoping for a method to use.  I'm sorry I should have been more specific.

What would the command(s) be for program 1 to run program 2?

 

After thinking about it, could that "sub" code exist in a library so that other programs could access and use it?

 

Thanks 

0 Likes
Message 4 of 11

ThomasRambach
Advisor
Advisor

You could just make a CommandMethod in the first DLL so that the user can run a custom command to launch the application directly from within AutoCAD. Does it really need to be a standalone executable or can they launch from within AutoCAD?

0 Likes
Message 5 of 11

mgorecki
Collaborator
Collaborator

Hi, I was hoping to have a sub of some kind in a library.  This sub will be passed some items.

I want multiple programs to have access to this one sub located in a library.

I have been looking for:

1.  How to create that loibrary part (is it a dll, or ?)

2.  How does a program call that particular function from the library part?

 

Thanks

0 Likes
Message 6 of 11

_gile
Consultant
Consultant

Hi,

From a standalone application (EXE) you cannot use the .NET API (you're stuck to the COM API).

IMHO, the simplest way would be defining a command (with CommandMethod attribute) from your 'sub' in the 'library' (DLL) so that you can netload this 'library' from the standalone application by invoking the NETLOAD command and launch your command.

You can see this example in the docs.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 11

mgorecki
Collaborator
Collaborator

Hi, after reading the replies, I have been thinking that the "standalone" option would not be the best approach.

I am now thinking that I need to create a "library" that would contain a number of "subs" that I use frequently in many of my applications.  Would that library be a .dll?  If so, could I attach it as a reference to multiple programs so they could just call those functions normally and pass them the appropriate items?

Would I be able to do that by attaching the "library.dll" using References, like I would the AcDbMgd.dll?

0 Likes
Message 8 of 11

_gile
Consultant
Consultant
Accepted solution

The library have to be a DLL.

You simply add it as reference to your projects setting the "copy locale" to true. The library have to be in the same folder as your project assemby. If you deploy your application, you have to join the library in the same folder.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 11

mgorecki
Collaborator
Collaborator

Hi Gilles, I'm going to try that.  Thanks

0 Likes
Message 10 of 11

mgorecki
Collaborator
Collaborator

Hi Gilles,

I've created a project "UtilitiesLibrary.dll" and in it I have some subs.  

I created a new project, and in the references I added "UtilitiesLibrary.dll".

I made a call to one of the subs in the library, but it tells me that its not declared and may be inaccessable due to its protection level.

How do I get it to see the functions/subs in the library?

0 Likes
Message 11 of 11

_gile
Consultant
Consultant

To be accessible, the classes and members of the library have to be 'public'.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes