与 SystemParametersInfo 签名冲突 [英] Conflict with SystemParametersInfo signatures

查看:62
本文介绍了与 SystemParametersInfo 签名冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就这样,运行这条指令:

Simply as this, to run this instruction:

NativeMethods.SystemParametersInfo(SPI.SPI_SETKEYBOARDCUES, 
                                   0UI, 
                                   True, 
                                   SPIF.None)

我需要这个签名:

<DllImport("user32.dll")>
Private Shared Sub SystemParametersInfo(
               ByVal uiAction As NativeMethods.SPI,
               ByVal uiParam As UInteger,
               ByVal pvParam As Boolean,
               ByVal fWinIni As NativeMethods.SPIF)

End Sub

但是要运行其他指令:

Dim MyBoolean As Boolean = False
NativeMethods.SystemParametersInfo(SPI.SPI_GETKEYBOARDCUES, 
                                   0UI, 
                                   MyBoolean, 
                                   SPIF.None)

...当然我需要 ByRef 布尔参数来检索值:

...Of course I need to ByRef the Boolean parameter to retrieve the value:

<DllImport("user32.dll")>
Private Shared Sub SystemParametersInfo(
               ByVal uiAction As NativeMethods.SPI,
               ByVal uiParam As UInteger,
               ByRef pvParam As Boolean,
               ByVal fWinIni As NativeMethods.SPIF)

End Sub

那么我需要如何管理这些签名?我不能只选一个.

So how I need to manage those signatures? I can't just choose one.

有一种方法可以将两个签名都保留为布尔值,而不会将其中一个更改为整数?

There is a way to keep both signatures as Boolean to don't change one of them to Integer?

是的,第一条指令不适用于 ByRef 参数,那么我该如何解决这个问题?

And yes the first instruction don't works with a ByRef parameter, then how I can fix this?

推荐答案

在 C# 中,您可以将两个版本都声明为重载方法.然后让编译器根据你是按值还是按引用传递参数来选择合适的.但是,VB 语法不允许您指定参数是按引用还是按值.在 C# 中,您必须包含 refout,因此重载解析器可以使用该信息来选择适当的方法.

In C# you would declare both versions as overloaded methods. And then let the compiler select the appropriate one depending on whether you pass the parameter by value or by ref. However, VB syntax does not allow you to specify whether the parameter is by ref or by value. In C# you have to include ref or out and so the overload resolver can use that information to pick the appropriate method.

我认为这意味着您需要定义两个名称不同的方法.例如:

I think this means that you need to define two methods with different names. For instance:

<DllImport("user32.dll", EntryPoint:="SystemParametersInfo")>
Private Shared Sub SystemParametersInfoByValBoolean(
               ByVal uiAction As NativeMethods.SPI,
               ByVal uiParam As UInteger,
               ByVal pvParam As Boolean,
               ByVal fWinIni As NativeMethods.SPIF)

End Sub

<DllImport("user32.dll", EntryPoint:="SystemParametersInfo")>
Private Shared Sub SystemParametersInfoByRefBoolean(
               ByVal uiAction As NativeMethods.SPI,
               ByVal uiParam As UInteger,
               ByRef pvParam As Boolean,
               ByVal fWinIni As NativeMethods.SPIF)

End Sub

这篇关于与 SystemParametersInfo 签名冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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