Is it possible to link any dll file with a c# program without knowing any details about it and to get details of the data and functions of it.I tried with explicit linking but i could not.If any one could please...
Thanks in advance
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
AlanRank #669 · 3.6K reputationPosted Aug 14, 2007, 1:21 AM EDT
No, you can only link managed dlls and then find out what they contain using reflection.
If you're wanting to examine unmanaged dlls, I'd use a tool such as dependency walker (depends.exe) which comes with VS or can be downloaded free from this site:
http://www.dependencywalker.com/
kandy22 reputationPosted Aug 14, 2007, 2:25 AM EDT
AlanRank #669 · 3.6K reputationPosted Aug 15, 2007, 8:57 AM EDT
Reflection is a huge subject but the following program shows how to display all the types in a dll (using System.Drawing.dll as an example) and then to list all the members in each type, 20 at a time if there are more than 20.
To use your own dll instead, you need to know its version, culture and publickeytoken as well as its simple name (without the .dll extension). If you haven't done anything special, then typically these will be: Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
using System;
using System.Reflection;
class Program
{
static void Main()
{
Console.Clear();
string dllName = "system.drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
Console.WriteLine("Examining assembly {0} ...\n", dllName);
Assembly assembly = Assembly.Load(dllName);
Type[] types = assembly.GetTypes();
Console.WriteLine("{0} type(s) found ...\n", types.Length);
for(int i = 0; i < types.Length; i++)
{
Type t = types[i];
MemberInfo[] mia = t.GetMembers();
Console.WriteLine("{0}, {1}, has {2} member(s), namely :\n", GetTypeKind(t), t, mia.Length);
for(int j = 0; j < mia.Length; j++)
{
Console.WriteLine("{0} is {1}", mia[j].Name, mia[j].MemberType);
if ((j + 1) % 20 == 0)
{
Console.WriteLine("\nContinue listing y/n ? \n");
char reply = Console.ReadKey(true).KeyChar;
if (reply == 'n' || reply == 'N') break;
}
}
if (i < types.Length - 1)
{
Console.WriteLine("\nLook at another y/n ? \n");
char reply = Console.ReadKey(true).KeyChar;
if (reply == 'n' || reply == 'N') break;
}
}
}
static string GetTypeKind(Type t)
{
if (t.IsClass)
return "Class";
else if (t.IsInterface)
return "Interface";
else if (t.IsEnum)
return "Enum";
else
return "Struct";
}
}