通过vb.net中的反射调用非汇编(非托管)dll中的方法?

发布于 2024-12-22 17:31:38 字数 714 浏览 2 评论 0 原文

我想使用反射在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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如歌彻婉言 2024-12-29 17:31:38

您不在非托管 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文