My C# and DLL Data Woes - c#

I'm trying to see if it is possible to pull data from a DLL. I did some research and found that you can store application resources within a DLL. What I couldn't find, was the information to tell me how to do that. There is a MS article that explains how to access resources within a satellite DLL, but I honestly don't know if that is what I'm looking for. http://msdn.microsoft.com/en-us/library/ms165653.aspx I did try some of the codes involved, but there are some "FileNotFoundExceptions" going on.
The rest of the DLL information is showing up: classes, objects, etc. I just added the DLL as a resource in my Visual Studio Project and added it with "using". I just don't know how to get at the meat of it, if it is possible.

If dlls are .net, you can use reflection.
Using System.Reflection;
....
Assembly A= Assembly.LoadFrom(YouDllFileName);
string[] STA;
STA= A.GetManifestResourceNames();
// STA contains all the resource names in the dll
...
// to extract them
Stream str= A.GetManifestResourceStream(STA[I]);
// then, you can make that stream became a file if you wish
You can also extract a .net assembly resources by using ildasm

I'm not totally sure what you might be running into based on your description, but a couple of general pointers...
If what you are trying to find is files you've added to the project you do this:
Right click on the resource in solution explorer, hit properties and set the "Build Action" to "Embedded Resource".
For strings and icons, add a .resx file to the project and insert them in there. If that's what you're doing and still running into issues, check the Build Action.

There is two types of dll.
Managed dll - dll that writen on any .net language (like csharp)
The link that you provide is working with managed dlls.
Unmanaged dll - classic c/cpp dll.
in this case you need to link between managed (your code) and unmanaged.
To find what the type of your dll, you need to add this dll as reference.
In visual studio open project, right click on references(in Solution Explorer).
Then "add reference"->browse-> add your dll.
Then at references, you can see your dll.
Right click on him, and add view in Object Browse.
If you see something like class "c" inside namespace "b", you working with managed dll.
In Object Browser you can learn a lot about your dll (maybe this is more important, than just extract resources)
At this point you can do the way that "Daniel Dolz" answer to you.

Since you say you are able to add the DLL in a using directive you can probably use the methods that the DLL exposes. If you do not have the documentation for the DLL then you may just have to try using the object browser to see what it has to offer.
assume:
using MyDll;
you should them be able to call the methods like this:
string x = MyDll.SomeType.GetValue();
is that what you were asking?

Related

How to create a dll that includes all the others?

At the moment of creating a project of type "Library of Classes, usually one can generate a dll when compiling, but how could I generate a dll without losing others that I already have included?
I explain with an example: It turns out that Nuget downloaded an S22.Imap dll with the one I worked with, later I generated the dll in the traditional way that I explained in the beginning, but when I wanted to work with dll in another computer, I got errors that were not I found functions that contained the S22.IMAP dll. So to solve this problem, I had to copy the dll of my project, S22.IMAP in an additional way in a specific path of the other computer.
My question is:
How could you generate a dll that includes the ones included in the project you were working with?
All the referred 3rd party dlls (S22.Imap.dll in your example) will be copied to the output folder together with your own dll file (let's say a.dll) when you build your project. That means you should always copy them together (S22 + a.dll) to the place you want to refer them, on another computer/folder/place.
If you really want to make them only one file (although it is not recommended), you can set the S22 one as some "nested resource". Then you will get only one a.dll file and the S22 one is inside the a.dll. See below page for some reference:
Embedding one dll inside another as an embedded resource and then calling it from my code
AND, ILMerge is some tool that can help you do so.
In general, you don't. A DLL is a dynamic linked library, and you would normally only combine static libraries during a build. Here is an answer on the difference between static and dynamic linking.
Typically you would include all the DLLs you need in the installer package. If you use Visual Studio to create the installer, it can detect the dependencies for you. When you run the installer, all of the necessary DLLs are deployed. Nearly all commercial .NET software follows this pattern.
It is possible to merge an assembly into another assembly using a tool called ILMerge. This would be a very unusual thing to do, and could cause issues with intellectual property and code signing, so it is not recommended.

C# Class Library method summaries not showing in intellisense of vb.net project

(VS 2008)
I'm using a C# library for my VB.NET project. And the method summary/notes or what they are called do not show in intellisense. Is this supposed to be like that? Or is there something I must do to fix it? And if not, will VS 2010 be able to do this?
EDIT: Still unresolved. Now building library dll + xml file, but how to import the xml file in my vb project?
See image: http://i52.tinypic.com/25kh5xw.png
In C# library, go to the properties on the build tab, and check the checkbox for including XML documentation and specify the name and path. After that include the new library in your VB.Net project.
one reason could be resolved by importing the namespace needed
another reason could be due to faulty writing
if you send the code where the problem is we might be able to help you
If you're using source control (TFS or Github) then you need to the following:
Check in ( Push) for safe return point (base line)
Delete the references from the project.
Delete the custom dll's from the solution.
At this point the libs are marked as [removed], if you would add them again at this point, they will just be marked as [changed] again. This did not include the summaries for me.
Check in (push). dll's are now removed from source control as well.
Drag and drop the dll's (including xml) into the solution (I recommend using this method for including dll's
Add references to these dll's via Browse.
Check if you have summaries.
Check in (push).

C# DLL noob, how to get functions

I've been given a dll to talk to a device, I have little to no experience in C# and I'm supposed to get the device initialized by the end of the week. The dll has methods to open ports and send messages, but I have no idea how to get access to the functions
I know its a bit ridiculous to ask but im running out of time.
Thanks,
Add a Reference to the .dll file in your C# project.
Add a Using namespace at the top of whatever class is going to interact with the .dll methods.
You will now be able to access the methods.
Edit: If your library is unmanaged you'll have to use Pinvoke.
Generally speaking, a feature to call from managed code into unmanaged code (which I assume your DLL is) is called P/Invoke and generally involves annotating required static extern methods with attributes.
Add a reference to the dll in your project (selet browse to find it) and you should be able to access the functions within. As for how to make your device work with it, I think you're on your own :)
If the DLL is a .Net assembly, you can load it into a Visual Studio project by adding it as a reference.
In the absence of documentation, it can also be extremely helpful to load the assembly into .Net Reflector, which lets you inspect the guts of the assembly, even to the point of disassembling the code inside the methods.
1- If it is managed Dll , i.e. Written using .net framework than calling a method from the dll is like you are calling a method from your own class.
just add the reference of the dll in your project and include the namespace reference by 'Using' keyword.
2- If it is not than you need to import your dll dynamically, you can use [DllImport]

Help understanding this C# library

Hi kind of a newbie question.
So apparently this library is popular for this sort of thing:
http://extracting.codeplex.com/
When I download that all I get is a .dll
I can't find documentation on their api, I don't know what I'm supposed to do with this .dll (I know how to load in functions from DLLs and such, but how when I don't even know whats in it?), can someone help me out.
start a new c# project. Open the add reference dialog and use the broswe tab, select the dll.
now open the object browser - you will see all the functions etc
edit: of course you can also download the source code from codeplex; always the ultimate form of documentation
There's a link on the same page pointing to the API documentation containing sample usage.
There is a link to an example on the codeplex site
http://extracting.codeplex.com/wikipage?title=Web%20Data%20Extracting%20and%20Analyzing%20Framework%20API&referringTitle=Home
They have limited documentation on the codeplex site, available here.
I would recommend checking that documentation to see if it meets your needs, and asking any addition questions in their Discussions Page.
To use the functionality of the DLL from your project, right click on your project file in the Solution Explorer and choose "Add Reference..". You will be presented with a dialog to choose the reference you want to add. To choose the DLL from this library, browse to it from the Browse tab.
Once you've added the reference, you won't notice a whole lot of difference - all adding a reference does is give you access to the classes that are defined withing that DLL (called an "Assembly" in .NET terms). Think of it like getting a new set of "built-in" classes in your project that you can now use. You'll want to find some documentation or ask for help on the site to learn how to use these classes.
if you are using visual studio, you can just include the dll into the reference folder of your project and then use the "using" keyword to include the library into your namespace ...
If this is a .NET assembly, then reflector will tell you what classes and methods are available. You can also reference the DLL from a C# project and then press "ctrl-alt-j" to bring up the object browser to see that data inside of Visual Studio.
You can download the source code from that page.
Look at the classes and namespaces. You can add a reference to the DLL to your project and add "using" with the namespace of the DLL to the top of any code files you need to use it in in order to have access to the classes.
Additionally you can look at some of the examples posted.
Load the dll into .net Reflector. This will list the contents of the dll and any code comments associated with the API.

Exposing the methods of a DLL in C#

After someone creates a DLL in C# using the Microsoft Visual development environment, how would another programmer take that code, make a new project that includes the DLL's source and make a GUI that uses the DLL'S API?
I have already done the following four steps:
1) In the Solution Explorer right-click "References" and select "Add Reference ...".
2) Select the "Browse" tab.
3) Navigate to the DLL and select it.
4) Add the appropriate "using" directive to the top of the code.
What is next? After I declare a new object, how do I see what methods to use?
View Menu -> Object Browser
You should be able to look at the objects/methods and so on contained in the DLL and publicly exposed.
You should be able to use intellisense and the object explorer as always. Without the source that will be your best bet.
I don't have any code off the top of my head but have you investigated the Reflection library?
You should be able to figure out and run everything you need with that...
you can load the DLL via the .NET Reflector tool from red-gate and see all of the api and even how it was implemented http://www.red-gate.com/products/reflector/
Well...
Suppose your library is called MyLib.DLL
You would do:
MyLib ml = new MyLib();
ml.YourMethodsShouldAppearHere(); //If they are public of course.
;)
You can open any .NET DLL in this 3rd party tool called ".NET Reflector". This tool will allow you to view all the types/methods/properties and even decompile the code contained in the DLL.
.NET Reflector is similar to the object browser in Visual Studio, but is way more powerful.
If you haven't tried Reflector yet, I highly recommend it (it's really easy to use)!

Categories

Resources