45342

Conflict with SystemParametersInfo signatures

Question:

Simply as this, to run this instruction:

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

I need this signature:

<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

But to run this other instruction:

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

...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?

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

Answer1:

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

Recommend

  • Disable Windows Visual Effects through SystemParametersInfo
  • Java: JNA SystemParametersInfo parameters type
  • callback function from unmanaged dll in VB .NET
  • About using arguments passed to the CheckedChanged event of Checkbox
  • Select Command with Multiple LIKEs
  • hiding rows in excel based on words in a cell
  • How to reduce the decimal length
  • Hexadecimal to 8-bit unsigned array in VB.NET
  • VBA to set Zoom level on Sheets
  • C# equivalent to VB6 'Type'
  • replace text in a string with .net regexp
  • ms-access save query result in a string
  • Solving the problem of SQLinjection
  • not able to Open Powerpoint using VBA
  • Can I include a Generic type parameter in a lamba expression? (VB.NET 2010)
  • .NET MVC3 Razor (VB!) Extensions not imported in view?
  • VBA, TRIM part of a Path
  • Text similarity analysis (Excel)
  • Sorting a DataTable using LINQ, when sort-by-columns may vary
  • VBScript to check for open process by user
  • Extend Name Box
  • Excel VBA URLDownloadToFile Error for https Ressource
  • Less Conflicting Session Manager for Zope 2
  • Need code translation from VB to C#
  • How to pass a value from ASP.NET MVC controller to ASP.NET webforms control inside MVC View?
  • Ubuntu and bcrypt
  • Implementing “partial void” in VB
  • System.InvalidCastException: Specified cast is not valid
  • How can I extract results of aggregate queries in slick?
  • OOP Javascript - Is “get property” method necessary?
  • Passing 1 of 3 values to a Sub
  • How to Cache Real-time Data?
  • Very simple C++ DLL that can be called from .net
  • PHP - How to update data to MySQL when click a radio button
  • Javascript + PHP Encryption with pidCrypt
  • Angular 2 constructor injection vs direct access
  • Getting Messege Twice Using IMvxMessenger
  • Bitwise OR returns boolean when one of operands is nil
  • How can i traverse a binary tree from right to left in java?
  • How can I use threading to 'tick' a timer to be accessed by other threads?