Nytro Posted August 9, 2009 Report Posted August 9, 2009 Creating and using DLL Filesby sunjesterUsing 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 name2. here you can copy & Paste the code from the previous two tutorials, below is what mine looks like now.//sunjester//fusecurity.comusing System;using System.Collections.Generic;using System.Linq;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.5. name it accordingly.6. now we add the reference to our DLL file we just created.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]); } } }} Quote
sunjester Posted September 2, 2009 Report Posted September 2, 2009 Hopefully people are actually reading these Quote
Gonzalez Posted September 3, 2009 Report Posted September 3, 2009 Yes, how are you sunjester. Didn't hear from you for a wile.-Gonzalez Quote