Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, September 14, 2016 1:13 PM
Hi, I am using VS2015. How to I use it to create a DLL and use it in my Project.
Please show me an example to do it and use it.
Thanks.
All replies (8)
Thursday, September 15, 2016 1:41 AM ✅Answered
Hi Sky Driving,
Steps for Creating DLL
Step 1:- File->New->Project->Visual C# Projects->Class Library. Select your project name and appropriate directory click OK.
After Clicking on button ‘OK’, solution explorer adds one C# class ‘Class1.cs’. In this class we can write our code.
When we double click on Class1.cs, we see a namespace CreatingDLL. We will be use this namespace in our project to access this class library.
Step 2:- Within Class1.cs we create a method named ‘demosum**’** that takes two integers value and return sum to which method passed numbers.
Step 3:- Now build the Application and see bin\debug directory of our project. ‘**CreatingDLL.dll’ **is created.
Now we create another application and take this DLL (CreatingDLL.dll) reference for accessing DLL’s method.
Step 4:- File->New->Project->Visual C# Projects->Web Form Application.
Step 5:- Designed your Web Form.
Step 6:- Add reference of DLL (CreatingDLL).
After adding reference of DLL, it will appear in References section.
Step 7:- Write code on button click of Web Form Application. Before creating object and making method of Add DLL, add namespace **CreatedDLL **in project as bellow code.
Step 8:- Now build the application and execute project.
Regards
Deepak
Wednesday, September 14, 2016 10:25 PM
(FWIW the name is 'assembly' in .Net, not 'dll')
If your code is valid c# then going to the 'Build' menu and choosing 'Build Solution' will create the assembly for you. By default each Project in your solution becomes an Assembly.
If one project adds a reference to another project (Right Click on references => Add Reference...) then it can be used in that project.
Thursday, September 22, 2016 11:02 PM
can you show me one example of DLL that accept parameters to output to caller.
the dll contain below code:
private async System.Threading.Tasks.Task<byte[]> getHttpAsBytesAsync(string url)
{
//build request
var request = WebRequest.CreateHttp(url);
request.UseDefaultCredentials = true;
byte[] bytes;
//get response
var response = await request.GetResponseAsync();
using (var br = new BinaryReader(response.GetResponseStream()))
{
using (var ms = new MemoryStream())
{
var lineBuffer = br.ReadBytes(1024);
while (lineBuffer.Length > 0)
{
ms.Write(lineBuffer, 0, lineBuffer.Length);
lineBuffer = br.ReadBytes(1024);
}
bytes = new byte[(int)ms.Length];
ms.Position = 0;
ms.Read(bytes, 0, bytes.Length);
}
}
return bytes;
}
private async System.Threading.Tasks.Task<BitmapImage> convertBytesToBitmapAsync(byte[] bytes)
{
//convert to bitmap
var bitmapImage = new BitmapImage();
var stream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
await stream.WriteAsync(bytes.AsBuffer());
stream.Seek(0);
//display
bitmapImage.SetSource(stream);
return bitmapImage;
}
Friday, September 23, 2016 12:54 AM
A dll does not accept parameters. An assembly is a file. Files do not take parameters. An assembly is a type of file which contains partially compiled code.
A method can accept parameters. The two methods you have shown are both examples of methods which accept a parameter and return a result to the caller. The methods you have shown (like all methods) would need to be stored in an Assembly (either .exe or .dll) in order to e called.
What are you trying to do?
What problem do you have?
Friday, September 23, 2016 2:20 AM
I wanted to create a DLL contain methods just like the pre-built class like System.IO or methods stored in an Assembly (either .exe or .dll) in order to e called.
This is for security reason. can you help to show how to do it?
Thanks
Friday, September 23, 2016 7:21 AM
Deepak has shown you the steps in tiny detail. Which exact step do you have a problem with? Tell us what you did, what happened and what you wanted to happen.
If you have a security problem that you want help with then you should tell us what the security issue is. Don't ask us how to implement a solution which is not actually going to solve your problem. Tell us the real problem.
Friday, September 23, 2016 1:55 PM
????
Step 7:- Write code on button click of Web Form Application. Before creating object and making method of Add DLL, add namespace **CreatedDLL **in project as bellow code.
Where to add this namespace?
Monday, September 26, 2016 9:06 AM
Hi Sky Driving,
you had asked where to add Namespace.
you need to add namespace at the top of the page where other namespace are mentioned.
then you can access and use the content and functions of that DLL in that page.
you can see in the picture to get the idea where you have to add namespace.
Regards
Deepak