Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi folks,

I want to load an unmanaged dll and get the method names inside the dll.
I have used reflection to do for managed dll.But not able to get it right for unmanaged code


Assembly asm = Assembly.LoadFrom(path);

Type[] mu = asm.GetTypes();

foreach (Type typeInfo in mu)
{
  MethodInfo[] mi = typeInfo.GetMethods();

  
  }



Please help
Regards,
Rajesh
Posted
Updated 13-Jul-11 3:43am
v3

To extend Shameel's answer:

COM components come with a type library, which describes the public interface that the component exposes. This is what the C# interop uses to build cover classes for COM, and it looks like you can use TypeLibConverter.ConvertTypeLibToAssembly[^] to create a .Net Assembly which you can then reflect on in the normal way.

OCXs/ActiveX controls are COM components with a graphical representation and the same game should work for them.

In general, though, unmanaged DLLs are not self describing, and it is therefore not possible to get full reflection information on them. You should be able to get a list of functions (check the Windows API to see if it has a method for it), but you won't be able to find parameters or return types because they are not specified anywhere.
 
Share this answer
 
Comments
explorerC 13-Jul-11 10:03am    
Bob,

Jus want to find the method names ,no parameters and return types
The dll is written in 'C' Language
BobJanova 13-Jul-11 10:39am    
With quick search I didn't find anything trivial. You can find the list within the DLL file in the .edata section. Have a look at the PE file format (used for .exe and .dll on Windows). I wrote some code to find this section a long time ago but I don't think I have it any more.
Sergey Alexandrovich Kryukov 13-Jul-11 17:22pm    
Good, my 5. As far as I remember, a type library does not have to be embedded in the COM executable module, but it can be. See also my comment to the answer by Shameel.
--SA
You can use the dumpbin and undname utilities as described here[^] to get the information (although not programmatically). Note that you need to use the /EXPORTS option to get the names from a DLL.
 
Share this answer
 
When it comes to managed DLL (assembly), you can use your code sample that uses Reflection to get the list of Types, methods, etc. Unfortunately in the unmanaged world, it is not so easy. There are various kinds of unmanaged DLLs like COM DLLs (also called ActiveX), native DLLs (Win32 API), etc. There is no standard equivalent for Reflection in unmanaged DLLs.
 
Share this answer
 
Comments
explorerC 13-Jul-11 9:41am    
thanks for the info...........
Sergey Alexandrovich Kryukov 13-Jul-11 17:20pm    
I don't think your answer is down-voted right now. I voted 5.
I must add that it is possible to "reflect" plain unmanaged DLL the the extent where you see all the exported names (by reading the PE structure of the module as binary dump utilities do). If the names are mangled, one can draw a conclusion of parameters but this is a already quite unreliable.
--SA
[no name] 14-Jul-11 0:28am    
yes, it is possible to some extent, what I meant was that there is no standard way of achieving this across all unmanaged DLLs. If COM DLLs have an embedded type library, you can use it to "reflect" the DLL. On the other hand, reflecting native DLLs is quite difficult, but there should be some tools to let you do that too.
Sergey Alexandrovich Kryukov 19-Jul-11 17:48pm    
Sure, we agree on that.
--SA
Ever heard of PInvoke[^]
 
Share this answer
 
Comments
explorerC 13-Jul-11 9:32am    
Yeah i heard of it .......I want to get the type information of dll .Methods names possibly
I guess PInvoke doesn't do that???
[no name] 13-Jul-11 9:33am    
PInvoke is for calling methods in native DLLs. The question pertains to using Reflection on unmanaged DLLs.
Manas Bhardwaj 13-Jul-11 9:39am    
hold on, aren't unmanaged/native dlls are same?
And the question is not about using reflection, but calling the methods within unmanaged dll.
If you agree, you should (re)consider you vote.
BobJanova 13-Jul-11 9:59am    
The question appears to be about an equivalent to reflection to me.
[no name] 13-Jul-11 12:13pm    
question is about reflection. btw, thanks for downvoting all my answers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900