Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (1)

Powered by Vanilla. Made with Bootstrap.
[C#] Creating and using DLL Files
  • Creating and using DLL Files
    by sunjester

    Using DLL files is to eliminate writing code over and over again. DLL's are often used for may things like file I/O. I will show you how to take the first two tutorials I've written in this section (read and writing text files) and put them both in a DLL file. Then, once the DLL is in our project I will show you how to use the read and write methods we placed inside the DLL.It's probably more feasible for .NET applications to utilize DLL's instead of rewriting so much code.

    C# and VB .NET applications are mostly used ("in the industry") for demo applications, or test applications for rapid application development. yes, c#, and VB.net are RAD languages just like the old VB6.

    1. first, create a new project. Open the wizard and select "Class Library" and give it an appropriate name

    http://i29.tinypic.com/mkyk2h.png

    2. here you can copy & Paste the code from the previous two tutorials (writing txt files & reading txt files), below is what mine looks like now.

    //sunjester
    //fusecurity.com
    using System;
    using System.Text;
    using System.IO;
    using System.Collections;
    namespace FileIO
    {
    public class InputOutput
    {
    //writing to text files
    public void writeToFile(string fileName, string content)
    {
    StreamWriter write = new StreamWriter(fileName);
    write.Write(content);
    write.Close();
    }

    //reading from text files
    public ArrayList Read(string fileName)
    {
    StreamReader read = new StreamReader(fileName);
    ArrayList lines = new ArrayList();
    while (!read.EndOfStream)
    {
    lines.Add(read.ReadLine());
    }

    read.Close();
    return lines;
    }
    }
    }
    3. now we can build the DLL, so in the menu select "Build" then "Build Solution".4. next, let's go ahead and add another project to this one just in case we need to go back to the original DLL source and update it.

    http://i28.tinypic.com/120jwra.png

    5. name it accordingly.
    http://i31.tinypic.com/ml6w48.png

    6. now we add the reference to our DLL file we just created.

    http://i25.tinypic.com/2cwsz1e.png

    http://i27.tinypic.com/5fngwn.png

    7. and the final code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using FileIO;
    using System.Collections;
    namespace UseFileIO2
    {
    class Program
    {
    static void Main(string[] args)
    {
    InputOutput io = new InputOutput();
    io.writeToFile(\"c:\\test44.txt\", \"here is some sample test data to write\");
    ArrayList lines = io.Read(\"c:\\test44.txt\");

    for (int i = 0; i < lines.Count; i++)
    {
    Console.WriteLine(lines[i]);
    }
    }
    }
    }
  • George
    Posts: 707
    Hello,

    Nice tutorial, thanks, may come in handy.

    Also, please don't copy and paste from other sites without giving copyrights.

    Regards,
    George.
  • Copy & paste from other sites? this is my tutorial...
  • George
    Posts: 707
    Hello,

    If this is your tutorial, great.

    I don't think it's possible to write tutorials like this with good screenshots in less than 2 minutes.

    Your other thread is the same.

    Funny when I search a few keywords the sites I come up with..

    Regards,
    George.
  • well, here is a link to MY forum with MY tutorial...
    http://fusecurity.com/forum/viewtopic.php?f=11&t=6

    and the other tutorial is so old it's from my blog.
    http://fusecurity.com/sunjester/2010/02 ... enter-key/

    (not everyone in the scene is a copy & paste noob, some of us actually do the work)
  • George
    Posts: 707
    Hello,

    I'm not going to register because I don't want to and it's member only thread, maybe you wrote it, maybe you didn't, I can't possible tell. All I know is I saw many pages for this on Google with the same first 50 words.

    I acept that your new here and are trying to get your post count up with good quality posts as most new people do, but it's good for sites to have exclusive content as well, otherwise there no different from other sites.

    Regards,
    George, Firewire Security Admin.