4

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Lynn
  • 160
  • 1
  • 8
  • Have a look at [this question](http://stackoverflow.com/questions/1192054/load-image-from-resources-in-c), and don't just read the accepted answer, read them all. – Igby Largeman Apr 15 '10 at 16:13
  • What kind of data do you want to pull out? Strings, bitmaps? Also, is this DLL created in .NET or other language like C++? – Nayan Apr 15 '10 at 16:14
  • The DLL I'm trying to add isn't mine and I have very, very little information about it. I know some of what it does, I know it is trusted and I can view that it has classes and objects. That is about it. I'm pulling strings out of the DLL. – Lynn Apr 15 '10 at 16:35
  • What strings are they? How do you know that they are in there? – Fyodor Soikin Apr 19 '10 at 21:31
  • The DLL was part of a interview quiz and they informed me the data was in the DLL. So, all I know is that I was supposed to be pulling information from a DLL. I never did figure it out. Thanks. – Lynn Apr 20 '10 at 18:12
  • You could peek into the DLL (to actually know what you're looking for) by using ILSpy. – Louis Kottmann Dec 10 '11 at 19:16

4 Answers4

1

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
  • 2,403
  • 1
  • 18
  • 23
  • In attempting this code (keep in mind, I'm fresh to C#), the "I" in Stream str= A.GetManifestResourceStream(STA[I]); is messing with me. What is it from and what does it do? – Lynn Apr 15 '10 at 16:49
  • STA[] is a array of strings, and I would be an index into that array. – Jason Berkan Apr 15 '10 at 18:43
0

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 L
  • 2,297
  • 17
  • 20
  • There is no "Build Action" in the Properties of the DLL when I look at it in Solution Explorer. – Lynn Apr 15 '10 at 16:37
0

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?

hal9000
  • 823
  • 10
  • 23
  • 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 Apr 21 '10 at 11:05
  • 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 :-) – hal9000 May 04 '10 at 15:02
0

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
  • 4,267
  • 33
  • 40