我想使用反射在vb.net中动态调用dll(不是程序集,非托管,可能是COM对象模型)。
我见过几种不同的方法来调用 .net 程序集的 dll 中的方法 - 但我还没有找到动态调用 dll 内部的方法(如 user32.dll 或 winmm.dll)的方法。我相信这会被称为后期绑定?
我问的原因是因为我正在构建一种语言,该语言将依赖于外部库来实现许多不同的功能。
一个例子(用我正在构建的这种语言):
Declare Function mciSendStringA using "winmm.dll" (strCommand As String, strReturn As String, returnLength As Integer, blah As Integer) As Integer
Declare Function WriteConsoleA using "kernel32.dll" (hConsoleOutput As Integer, lpBuffer As String, numberofcharstowrite as Integer, lpReserved as Integer) As Boolean
当我在 winmm.dll 中构建调用 mciSendString 的解释器时,如何使用反射来处理这个问题?我希望用户能够引用他们想要的任何 dll/方法。
我可以得到一些正确方向的指导吗?也许甚至是一些我可以拆解并理解的 vb.net 代码?
I want to use reflection to dynamically call a dll (not an assembly, non-managed, possibly COM object model) in vb.net.
I've seen several different methods of calling a method in a dll that is a .net assembly - but I have not found the way to dynamically call a method inside of a dll like user32.dll or winmm.dll. I believe this would be called late-binding?
The reason I'm asking is because I am building a language that will depend on external libraries for lots of different functionality.
An example (in this language I'm building):
Declare Function mciSendStringA using "winmm.dll" (strCommand As String, strReturn As String, returnLength As Integer, blah As Integer) As Integer
Declare Function WriteConsoleA using "kernel32.dll" (hConsoleOutput As Integer, lpBuffer As String, numberofcharstowrite as Integer, lpReserved as Integer) As Boolean
When I build the interpreter for the call to mciSendString in winmm.dll, how can I use reflection to handle this? I want the user to be able to reference any dll/method they wish.
Can I get some guidance in the right direction? Perhaps even some vb.net code that I can take apart and understand?
发布评论
评论(1)
您不在非托管 Win32 本机库上使用反射。
相反,您加载它们并检索指向非托管函数的指针以通过地址调用它们。这是在 C# 中执行此操作的方法:
http://blogs.msdn.com/b/jonathanswift/archive/2006/10/03/dynamically-calling-an-unmanagement-dll-from-.net-_2800_c_23002900_.aspx
You don't use reflection on unmanaged Win32 native libraries.
Instead, you load them and retrieve pointers to unmanaged functions to call them by address. This is how to do this in C#:
http://blogs.msdn.com/b/jonathanswift/archive/2006/10/03/dynamically-calling-an-unmanaged-dll-from-.net-_2800_c_23002900_.aspx