I've really no idea where to start. I want to make my own dll to make some programming easier for me and a friend who's also getting into the c# scene.
I created a class library in a new project which is the dll.
So like maybe an example of a dll would help is all.
Thanks in advance!
Well, it depends on what the dll is for. i.e. You can make a dll that provides the functionality of a binary tree (i.e. class BinaryTree). Then using that dll will allow you to have the class BinaryTree in any project you want. So basically you implement the class BinaryTree in the class library project while you use another project to test it properly (yes, 2 projects in the solution). In this case in the testing project you need to add a reference to the dll project. Just right click on the References folder in your Solution Explorer, choose "Add Reference", the open the tab Projects and select your class library.
There's just one problem. Creating a dll that is really well portable into any project isn't simple. You have to create a good interface or else there's not really a point in making a dll.
Well like I know how to add dll's to my projects and use methods from them because I have a Zip extracting dll I found on google.
I just wanted to code one to see how it turned out but I tried and when I added the dll it was as if the method wasnt actually in it. So thats why I need help. I tried google havent found anything helpful yet then again I fail when it comes to google.
Anyways I'm gonna look into it some more and see what happens.
Then try making a dll for a list. It's not complicated.
Woo hoo! K well I fixed what I messed up, it wasnt reading the method because I placed it as private instead of public.
anyways my dll now reads from a text file!
String text = GGDLL.Read(file);
It works :)
Lol anyways I'm gonna play around and see what else I can add.
Don't forget to set the publicly available classes as public. If you don't set them explicitly as public, they won't be visible outside the dll.
Okay need some more help. Here's my code so far. This is just a test and for some reason its not working.
namespace GGLib
{
public class Lib
{
public void Test(string test)
{
StreamWriter sr = new StreamWriter(@"C:\test.txt");
sr.Write(test);
sr.Close();
}
}
}
Now I created a whole new project, added the dll and the method does not show up. Did I not do something right? I lost my other dll's source.
so you added a reference to the dll and a using GGLib line?
yea here's my code in my totally different project
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GGLib;
namespace GGLib_Form
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Lib.Test("This is a test";
}
}
}
But the method doesnt exist. The Lib part does but not the .Test
I have absolutely no experience with C#, but it looks like you've defined it as an instance method and you're trying to call it from the class.
should be
and fix your parenthesis
Lib.Test("This is a test";
This code:
Lib instance = new Lib();
instance.Test("This is a test");
goes with this type of method definition:
This code:
Lib.Test("This is a test");
goes with this type of method definition:
public static void Test(...)
And if you don't plan on instantiating the class, you should make it static as well.
Just to clarify for you, this is similar to
def method(argument)
print argument, "\n"
end
vs.
def self.method(argument)
print argument, "\n"
end
and
vs.
Though obviously the static class is missing the mix-in features of Module.
Yeah, that's pretty much it. Though, just like in Ruby you can bind static methods to non-static classes.
Okay thanks guys it works perfectly now :) *lv's up LF and Blizz*