https://www.youtube.com/watch?v=BFO_luxmo5U&feature=em-uploademail
I wish to know the function of Dynamically Linked Library (DLL) in C#, particularly related to above reference. In the above link around 1:59 position author is talking about DLL.
Loading

VulpesPosted Dec 10, 2014, 9:29 AM
A DLL itself is not executable since it has no Main method.
In the video, the DLL is being used to house a static class containing extension methods.
Extension methods don't have to be included in a separate DLL but it's a good way of sharing the functionality between a number of applications.
VulpesPosted Dec 12, 2014, 11:06 AM
There's no entry-point i.e. Main() method in a DLL.
MahaPosted Dec 12, 2014, 8:38 AM
VulpesPosted Dec 11, 2014, 4:27 PM
Type this at the command prompt:
notepad DemoExecutable.cs
Now compile the executable whilst referencing the DLL:
csc /r:DemoLibrary.dll DemoExecutable.cs
If you now type:
dir
you'll see DemoExecutable.exe has been added to the folder.
Finally, run the executable by typing:
DemoExecutable
and the output will be:
And basically that's all there is to DLLs though the ones you'll encounter in practice will, of course, be much more complicated than this.
MahaPosted Dec 11, 2014, 2:19 PM
VulpesPosted Dec 11, 2014, 11:03 AM
You should be able to find this from the Start menu under Visual Studio tools.
First of all create a folder for your C# projects by typing this (always press return after each line when in the command prompt):
md c:\csprojects
Next type this to change the working folder to the one you've just created:
cd c:\csprojects
Next type:
notepad DemoLibrary.cs
and when notepad opens up, press OK to create a new file, paste this code into it and save it:
using System;
namespace DemoLibrary
{
public class Demo
{
public void SayHello()
{
Console.WriteLine("Hello from DemoLibrary");
}
}
}
Now type the following at the command line to compile the DLL:
csc /t:library DemoLibrary.cs
If you now type:
dir
You should see DemoLibrary.dll in the listing with a size of 3072 bytes.
Although it may not mean much to you, you can inspect the CIL and metadata in this DLL by typing the following:
ildasm DemoLibrary.dll
Once you've got this far, I can show you to how to reference the dll from an exe, if you like.
MahaPosted Dec 11, 2014, 10:20 AM
using System;
namespace DemoLibrary
{
public class Demo
{
public string Test;
}
}
VulpesPosted Dec 11, 2014, 9:29 AM
The writer of the DLL might also want to provide written documentation, including examples, on similar lines to what Microsoft do for the .NET framework.
It's possible to generate documentation automatically if you include documentation comments (three forward slashes instead of two) in your source code.
MahaPosted Dec 11, 2014, 9:22 AM
VulpesPosted Dec 11, 2014, 8:33 AM
Also, as it's a .NET DLL, it contains CIL (common intermediate language) and metadata rather than native code. The CIL is then converted to native code, method by method, when they are invoked within the DLL for the first time.
However, unless it's been obfuscated, it's possible to use a decompiler such as Redgate .NET reflector to recover the source code in a readable form. The only things of importance that can't be recovered are the original local variable names and any comments.
MahaPosted Dec 11, 2014, 8:10 AM
VulpesPosted Dec 10, 2014, 5:23 PM
He then compiled it to a DLL and added a reference to the DLL to his console project.
This enabled him to instantiate the Demo class and access its Test field from the console project.
So the source code is already in class library (i.e. DLL) form and can't be executed directly because there's no Main method.
To test a class library, you always have to compile it to a DLL and then reference it from an executable project. However, the executable project can be in the same solution as the class library and I think he did an example of that later in the video.
MahaPosted Dec 10, 2014, 4:52 PM
I wish to know how below source code is look like in DLL form.
using System;
namespace DemoLibrary
{
public class Demo
{
public string Test;
}
}
VulpesPosted Dec 10, 2014, 4:27 PM
Can you clarify please.
MahaPosted Dec 10, 2014, 3:19 PM
MahaPosted Dec 10, 2014, 10:39 AM