加载非托管dll并获取其中的方法 [英] Loading unmanaged dll and get the methods inside it

查看:94
本文介绍了加载非托管dll并获取其中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想加载非托管dll并获取dll中的方法名称.
我已经使用反射对托管dll进行了处理,但无法正确处理非托管代码


Assembly asm = Assembly.LoadFrom(path);

Type[] mu = asm.GetTypes();

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

  
  }




请帮忙
问候,
Rajesh

解决方案

扩展Shameel的答案:

COM组件带有一个类型库,该库描述了该组件公开的公共接口.这就是C#互操作程序用来为COM构建覆盖类的方法,看起来您可以使用 TypeLibConverter.ConvertTypeLibToAssembly [ ^ ]来创建.Net程序集,您可以按常规方式对其进行反思.

OCX/ActiveX控件是具有图形表示形式的COM组件,并且相同的游戏也适用于它们.

但是,通常来说,非托管DLL并不是自我描述的,因此不可能获得关于它们的完整反射信息.您应该能够获得函数列表(请检查Windows API以查看其是否具有方法),但是由于在任何地方都未指定参数,因此您将无法找到参数或返回类型.

您可以使用 dumpbin undname 实用程序,如 ^ ]来获取信息(尽管不是以编程方式).请注意,您需要使用/EXPORTS选项从DLL中获取名称.


涉及托管DLL(程序集)时,可以使用使用Reflection的代码示例来获取类型,方法等的列表.不幸的是,在不受管理的世界中,这并不是那么容易.有各种各样的非托管DLL,例如COM DLL(也称为ActiveX),本机DLL(Win32 API)等.在非托管DLL中,没有等效的反射标准.


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

解决方案

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.


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.


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.


这篇关于加载非托管dll并获取其中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆