重载解析失败? [英] Overload resolution failed?
问题描述
这行代码存在一些问题
I am having some problems with this line of code
If RegQueryValueEx(hKey, Value, 0, pdwType, Nothing, pvSize) = ERROR_NONE Then
对于任何了解注册表的人,我想知道如何更正此行,以便它与我的vb.net应用程序一起使用.
函数中未列出的变量是
to anyone with knowledge about the registry I would like to know how to correct this line so that it works with my vb.net application.
the variable not listed in the function is
Private Const ERROR_NONE As Integer = &H0
这里又是一个完整的功能
And here it is once more as a full function
Public Function ValueExists(ByVal RootKey As ROOT_KEY, ByVal SubKey As String, ByVal Value As String) As Boolean
Dim hKey As UIntPtr = UIntPtr.Zero
Dim pvSize As UInteger = 0
Dim pdwType As UInteger = CUInt(VALUE_TYPE.REG_NONE)
Try
If RegOpenKeyEx(RootKey, SubKey, 0, KEY_QUERY_VALUE, hKey) <> ERROR_NONE Then
Return False
End If
Return (RegQueryValueEx(hKey, Value, 0, pdwType, Nothing, pvSize) = ERROR_NONE)
Finally
If hKey <> UIntPtr.Zero Then
RegCloseKey(hKey)
End If
End Try
End Function
我已将其从C#转换为vb.net,但完整显示错误
错误3重载解析失败,因为对于这些参数,没有可访问的"RegQueryValueEx"是最特定的:
``公共共享函数RegQueryValueEx(hKey作为System.UIntPtr,lpValueName作为字符串,lpReserved作为整数,ByRef lpType作为UInteger,ByRef lpData作为字节,ByRef lpcbData作为UInteger)作为整数''
``公共共享函数RegQueryValueEx(hKey作为System.UIntPtr,lpValueName作为字符串,lpReserved作为整数,ByRef lpType作为UInteger,lpData作为System.Text.StringBuilder,ByRef lpcbData作为UInteger)作为整数'':并非最具体. C:\ Users \ Admin \ Desktop \ cLightning.vb 1095 24
I have translated this from C# to vb.net but get the error in full
Error 3 Overload resolution failed because no accessible ''RegQueryValueEx'' is most specific for these arguments:
''Public Shared Function RegQueryValueEx(hKey As System.UIntPtr, lpValueName As String, lpReserved As Integer, ByRef lpType As UInteger, ByRef lpData As Byte, ByRef lpcbData As UInteger) As Integer'': Not most specific.
''Public Shared Function RegQueryValueEx(hKey As System.UIntPtr, lpValueName As String, lpReserved As Integer, ByRef lpType As UInteger, lpData As System.Text.StringBuilder, ByRef lpcbData As UInteger) As Integer'': Not most specific. C:\Users\Admin\Desktop\cLightning.vb 1095 24
推荐答案
最有可能的问题是参数Nothing
.这是一个空指针,由于有多个名为RegQueryValueEx
的方法,因此无法弄清楚您暗示的是哪种类型,并且该Nothing
可以解释为一种或另一种类型,因为您的Nothing
可能意味着任何参考.
该怎么办?我不知道您的声明(请参阅我对问题的评论;它是P/Invoked Windows API吗?为什么?),但是您需要使用StringBuilder
实例的任一字节数组.声明一个类型和另一类型的变量,使用Nothing
对其进行初始化,然后将此明确定义的变量传递给该方法.这是解决此类问题的常用方法.
此代码中还有其他问题.您返回此方法的返回结果,该结果为整数,但是ValueExists
期望为布尔值.
但是,您根本不需要这些东西.使用.NET类Microsoft.Win32.Registry
和相关类,停止折磨自己:
http://msdn.microsoft.com/en-US/library/microsoft.win32. Registry.aspx [ ^ ].
回答后续问题:
清理注册表并不容易,也不安全.我将从找到一个好的注册表修复程序开始.这样的程序应该是可以备份所有注册表并还原它的程序.由于可以将注册表弄乱到无法启动或无法正常运行操作系统的地步,因此该修复程序应从闪存驱动器或其他设备启动其自己的操作系统.
我不知道确切使用什么,但100%确信这是可能的.我将从这里开始寻找:
http://en.wikipedia.org/wiki/List_of_data_recovery_software [ http://en.wikipedia.org/wiki/List_of_tools_to_create_Live_USB_systems [ http://en.wikipedia.org/wiki/System_Restore [
Most likely, the problem is in the parameterNothing
. This is a null pointer, and it''s not possible to figure out what type do you imply, because there is more than one method namedRegQueryValueEx
, and thisNothing
can be interpreted as one or another type, because yourNothing
might mean any reference.
What to do? I don''t know your declarations (please see my comment to the question; is it P/Invoked Windows API? Why?), but you need to use either array of bytes of the instance ofStringBuilder
. Declare a variable of one and another type, initialize it withNothing
and pass this explicitly defined variable to the method. This is a usual way of resolving such issues.
There are other problems in this code. You return the return result of this method, which is integer, butValueExists
expects Boolean.
However, you don''t need that stuff at all. Use the .NET classMicrosoft.Win32.Registry
and related classes, stop torturing yourself:
http://msdn.microsoft.com/en-US/library/microsoft.win32.registry.aspx[^].
Answering a follow-up question:
Cleaning the registry is not easy and not safe. I would start from finding a good registry repair program. And such program should be the one which can backup all the registry and restore it. As you can screw up the registry to the point where you cannot boot or normally operate your OS, this repair program should boot its own OS from a flash drive or something.
I don''t know what exactly to use but 100% sure this is possible. I would start looking from here:
http://en.wikipedia.org/wiki/List_of_data_recovery_software[^],
http://en.wikipedia.org/wiki/List_of_tools_to_create_Live_USB_systems[^],
http://en.wikipedia.org/wiki/System_Restore[^].
It''s hard to say where to start with the registry clean up. I have tried only a limited subset of cleaning. For example, you can locate all references to file system objects and detect those pointing to non-existing files/directories. These entries should be eventually removed, but first, you need to walk the registry to remove the entries where the entries you would remove are used and do it all recursively. Again, this is not easy and not safe. Thoroughly plan each step and theoretically calculate possible adverse effects, back up…
Sorry, probably I did not get it: if you not going to modify the registry, you are safe. Anyway, I hope the notes of could be useful.
—SA
这篇关于重载解析失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!