views:

189

answers:

4

Hey guys,

I'm a very beginner C# coder. So, if I get some of the terms incorrect, please be easy on me.

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.

Thanks, Lynn

+1  A: 

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

Daniel Dolz
In attempting this code (keep in mind, I'm fresh to C#), the "I" inStream str= A.GetManifestResourceStream(STA[I]);is messing with me. What is it from and what does it do?
Lynn
STA[] is a array of strings, and I would be an index into that array.
Jason Berkan
A: 

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.

Jim Leonardo
There is no "Build Action" in the Properties of the DLL when I look at it in Solution Explorer.
Lynn
A: 

Since you say you are able to add the DLL in a using statement 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.GetValue();

is that what you were asking?

Hal Diggs
This is a confusing reply; `using MyDll;` (a using *directive*, btw; not a using *statement*) must refer to a namespace; namespaces don't have methods - only types. So you'd need `string x = SomeNamespace.SomeType.GetValue()` *assuming* the methods are static.
Marc Gravell
Sorry Marc. I thought it was clear enough to make sense but I was in a hurry. I shall strive to make you happy in the future :-)
Hal Diggs
A: 

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.

Avram