Hi there,
I have never worked with dlls and i just started working with C#. i have never really worked with any programming languages that has anything to do with dlls.
I have to do couple of things.
project 1 : dll
project 2 : exe (loads dll)
step 1: I have to write a dll method returns "hello world"
step 2: import this dll into exe project 2
step 3: have exe display return from dll method
I am so lost :S ur help will be highly appreciated thank you
I have never worked with dlls and i just started working with C#. i have never really worked with any programming languages that has anything to do with dlls.
I have to do couple of things.
project 1 : dll
project 2 : exe (loads dll)
step 1: I have to write a dll method returns "hello world"
step 2: import this dll into exe project 2
step 3: have exe display return from dll method
I am so lost :S ur help will be highly appreciated thank you
ShaniPosted Nov 16, 2007, 3:45 PM
AlanPosted Nov 16, 2007, 3:27 PM
ShaniPosted Nov 16, 2007, 2:58 PM
AlanPosted Nov 16, 2007, 1:42 PM
To do that, youll need to start a new Windows Control library project in Visual Studio. Now place a button and a label on the control's surface just as you would do if the control were a form. Next double click the button in the designer and, in the click eventhandler method which opens up, place this line:
label1.Text = "hello world";
Then build the project but don't run it. A .dll will be created for your control library which will include (by default) UserControl1.
Next start a new Windows Forms project, right click on the ToolBox and select Choose Items. Then browse to where your .dll is stored and add UserControl1 to the ToolBox.
Finally, drag an instance of your control from the ToolBox to the form and build and run the project. When you click on the button, you should see "hello world" displayed in the label on the usercontrol.
ShaniPosted Nov 16, 2007, 11:14 AM
okay that is done =]
now i have to do the following...i kind of got started buh need ur help....naw clear on this
1)I have to create a conrtol that will display "hello world" when the button is pressed. 2)load this control from dll into exe 3)run and test imported control panel
Thanks for your help in advance =]
ShaniPosted Nov 16, 2007, 10:52 AM
AlanPosted Nov 15, 2007, 5:08 PM
Hi Shani,
Just add this line to the exe to see something on the screen:
Console.WriteLine (mystring);
ShaniPosted Nov 15, 2007, 4:04 PM
Thanks Alan =] well i like your approach
I made a dll like this...
[CODE]
namespace
mynamespace{
public static class mydllClass
{
public static string GetMeString(){
return "Hello World";}
}
}
[/CODE]
and then add this peice of code into my exe
string mystring=mynamespace.mydllClass.GetMeString();
it worked lol but didn't display hello world. may be something wrong :(
but thanks for your reply!!
AlanPosted Nov 15, 2007, 3:18 PM
dlls are just libraries of classes which you can use from exes or other dlls. From the coding point of view, unlike exes, they don't need a Main() method.
So, if you're using Visual Studio, start up a new 'class library' project, give it a name (lets say ClassLibrary1 for sake of illustration) and add the following method to Class1:
public void MyMethod()
{
Console.WriteLine("hello world");
}
Then build your dll project but don't try to run it.
Now start up a new console application project, give it a name and add a reference to the dll you've just created. To do this, right click on the name of your project in Solution Explorer, select Add Reference and look for the dll under the Recent tab and OK that.
Next place this line just after your other 'using' directives:
using ClassLibrary1; // the namespace used in ClassLibrary1.dll
and place these lines in your Main() method:
Class1 c1 = new Class1();
c1.MyMethod();
Console.ReadLine(); // to pause the display before the console closes
Finally, build and run your console application and, hopefully, a console window will open up and the immortal words will appear :)