VB.NET - 调用 Kernel32.DLL 的 Wow64DisableWow64FsRedirection
查看 Microsoft 的 Wow64DisableWow64FsRedirection 页面,我看到一些 C 代码。如果您想调用此函数并且它是从 VB.net 恢复的,该怎么办?
到目前为止,我已经这样做了:
<Runtime.InteropServices.DllImport("KERNEL32.DLL", EntryPoint:="Wow64DisableWow64FsRedirection")> _
Public Shared Function DisableWow64Redirection() As Boolean
End Function
并且我对 Revert 兄弟函数也做了同样的事情。
我这样称呼它:
DisableWow64Redirection()
这似乎有效,因为我调用的 shell 命令实际上在 system32 中找到了它的 exe,但我不确定恢复,它是否需要参数?此还原页面似乎需要我从禁用中获取输出并将其插入到恢复调用中。听起来对吗?如何更改 DLLimport 以接受布尔值并在 Kernal32.DLL 函数中实际使用它?
谢谢!
Looking at Microsoft's page on Wow64DisableWow64FsRedirection, I see some C code. What if you want to call this function and it's revert from VB.net?
So far I have done this:
<Runtime.InteropServices.DllImport("KERNEL32.DLL", EntryPoint:="Wow64DisableWow64FsRedirection")> _
Public Shared Function DisableWow64Redirection() As Boolean
End Function
And I do likewise for the Revert brother function.
I call it like so:
DisableWow64Redirection()
This seems to work, as the shell command I call after actually finds its exe in system32, but I am not sure about the Revert, does it need a parameter? This Revert page seems to want me to take the output from disable and plug it into the revert call. Does that sound right? How do I change my DLLimport to take in a boolean and actually use it in the Kernal32.DLL function?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将函数定义更改为
并定义 Revert(),如下所示:
您可以像这样调用它们:
我不是 VB.NET 人员,所以也许某些语法不正确 - 重要的是您提供了一个引用参数IntPtr 类型,映射到 PVOID 本机类型。您需要保留它,并将相同的值传递给 Revert()。
You could change your function definition to
and define Revert() like so:
You'd invoke these like so:
I'm not a VB.NET guy, so maybe some syntax is incorrect - the important thing is that you provide a reference parameter of IntPtr type, which maps to the PVOID native type. You'll want to hang on to it, and pass the same value to Revert().
声明是错误的,它需要一个 (ByRef oldValue As IntPtr) 参数。您需要将其传递给恢复函数。
但是,您无法在 .NET 程序中安全地使用它。它还会影响 CLR,它将无法再找到 .NET 框架程序集。您无法预测它们何时加载。肯定有更好的方法来完成你所需要的,对此提出一个新问题。
The declaration is wrong, it takes a (ByRef oldValue As IntPtr) argument. Which you need to pass to the revert function.
However, you cannot safely use this in a .NET program. It also affects the CLR, it won't be able to find .NET framework assemblies anymore. You cannot predict when they get loaded. There are surely better ways to accomplish what you need, start a new question about that.