How to create a simple dll in C# (Visual Studio 2005)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
this time I am interested in console applications only.
Now I need to create a simple .dll. How to do that? I am totally newbie in
dll creation so be patient ;) I have searched internet but I still do not
understand few things. please tell me how to write a very simple dll
containing only a function that writes a text on console. the text will be a
paremetr of this function. how to use that .dll in other applications.
any help will be really appreciated!
 
Create a class library project and write a simple class containing only
a function. you should make sure that you have added access control on
the function with PUBLIC. Now, create another console applicaiton and
add project reference from class library project.
You can invoke the function here after initializing a new instance of
the simple class.

Find more information at MSDN.

Sincerely,
simida
 
OK; procedure is as below; however, note that I wouldn't recommend writing
to the console from a dll except for trivial apps; the design principle of a
dll is that it could be consumed from various projects, which may or may not
have a console window attached - so generally I would only write to the
console from the UI (the console exe), with the dll conveying messages back
to the exe via some combination of interfaces, streams, events, trace, or
suchlike.


1: create the two projects
Create a new Console Application (exe) project (File -> New Project) and
then add a Class Library (dll) project (File -> Add -> New Project).
2: reference the dll from the exe
In the solution explorer of the console app, right-click on References ->
Add Reference...; on the Projects tab select the class library project
(note; different reference types are available)
3: write some code in the dll
e.g. in the Class1.cs that the designer provides:
namespace ClassLibrary1 {
public class Class1 {
public static void WriteSomething(string something) {
Console.WriteLine(something);
}
}
}
4: consume that method from the exe, e.g. in the Program.cs that the
designer provides:
static class Program { // I have tweaked these slightly for simplicity
static void Main() {
ClassLibrary1.Class1.WriteSomething("abc");
}
}

5: test
You should see abc written to the console
 
how can i make simple dll in visual studio 2005 so that i make my one
db class namespace in one dll
 
how can i make simple dll in visual studio 2005 so that i make my one
db class namespace in one dll

Just create a new Class Library project and put your classes in that -
the output of that will be a DLL.
 

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