Using a .dll

  • Thread starter Thread starter TomC
  • Start date Start date
T

TomC

I'm coming from a Java background, and exploring C#. An acquaintance
gave me a .dll that I plan on using in a couple of projects. His
directions involved putting a copy of the .dll in the folder where my
project is and adding a reference to it. I've gotten everything to
work just fine, but I've got a few general questions regarding the use
of .dll's in this fashion. Unfortunately, my acquaintance has gone on
vacation, so I hope that I might be able to get my questions answered
here.

Just to be clear, the questions are NOT about any specific .dll, but
rather using .dll's in any .NET program.

Question 1: If I create a program using a .dll and want to use it on
a different machine, I assume that I need to send a copy of the .dll
as well. Am I correct?

Question 2: If the answer to #1 is yes, does the .dll need to be in
the same place relative to the .exe file that was when I created it?
If so, then should I be putting it in the Release sub-folder and
referencing it there?

Question 3: I'm accustomed to .dll's being stored in the Windows
folder. Could I put a copy of a.dll that I'm using there instead of
in each project folder, and reference to it there? If so, should I?

Question 4: Some of the things that I may be doing will be done in a
networked environment. The source code will be on the network. How
might that affect the answers to any of my other questions?

Thanks in advance!
 
TomC said:
Question 1: If I create a program using a .dll and want to use it on
a different machine, I assume that I need to send a copy of the .dll
as well. Am I correct?
Yes.

Question 2: If the answer to #1 is yes, does the .dll need to be in
the same place relative to the .exe file that was when I created it?
If so, then should I be putting it in the Release sub-folder and
referencing it there?

Put the dll file in the same dir as your exe file.

That is the simplest.
Question 3: I'm accustomed to .dll's being stored in the Windows
folder. Could I put a copy of a.dll that I'm using there instead of
in each project folder, and reference to it there? If so, should I?

Not in the windows folder.

You could put it in GAC to achieve the same.
Question 4: Some of the things that I may be doing will be done in a
networked environment. The source code will be on the network. How
might that affect the answers to any of my other questions?

Where the source code is should not effect anything.

Arne
 
Thanks for the information. I do need to clarify one of your answers.
Put the dll file in the same dir as your exe file.

That is the simplest.
So do you mean that when I'm building the app, the .dll should be in
the bin/Release folder where the .exe will end up? Or do you mean
that it doesn't matter where it is when I build it, but when I
distribute it, put the .dll in the same folder as the .exe?
 
TomC said:
So do you mean that when I'm building the app, the .dll should be in
the bin/Release folder where the .exe will end up? Or do you mean
that it doesn't matter where it is when I build it, but when I
distribute it, put the .dll in the same folder as the .exe?

The last.

Arne
 
You should look at creating a setup project in your solution. They are
fairly straight forward to create and will take care of dependencies with
distribution.
 
You should look at creating a setup project in your solution. They are
fairly straight forward to create and will take care of dependencies with
distribution.

By setup project, I assume that you mean an installation routine -
often called setup.exe. I'm new enough to Visual Studio, I didn't
know such a feature was available. Thanks!
 
Yes, as long as you are not using an "express" version, then you can add a
new setup project to your solution. It will create at least a setup.exe and
an install.msi file.
 
TomC said:
Question 1: If I create a program using a .dll and want to use it
on
a different machine, I assume that I need to send a copy of the .dll
as well.

Right, unless it's already on that machine.
Question 2: If the answer to #1 is yes, does the .dll need to be in
the same place relative to the .exe file that was when I created it?
If so, then should I be putting it in the Release sub-folder and
referencing it there?

The DLL doesn't have to be in any specific place. This page explains
how Windows finds a DLL:
http://msdn2.microsoft.com/en-us/library/ms682586.aspx

One of my DLLs is full of astronomical routines. It's shared by
programs in several different folders, so I keep it in a folder in My
Documents. I added a PATH environment variable (this can be done in
the Control Panel) directing Windows to look there. Since I'm the sole
developer and user, it's convenient to have the DLL and its source
code in one spot.
Question 3: I'm accustomed to .dll's being stored in the Windows
folder. Could I put a copy of a.dll that I'm using there instead of
in each project folder, and reference to it there? If so, should I?

I prefer to not mess with anything in the Windows folder. My
philosophy is that this belongs to the system -- hands off.
 
Yes, as long as you are not using an "express" version, then you can add a
new setup project to your solution. It will create at least a setup.exe and
an install.msi file.

Ah, that explains things. I am using the express version.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top