RegQueryInfoKey:错误87 - “参数不正确”

时间:2015-04-14 13:20:33

标签: winapi vb6 registry

我有以下VB6代码尝试枚举注册表子项。这适用于我尝试过的所有计算机,除了我尝试设置为开发计算机的一台新Windows 7 VM。

这是Windows 7专业版,所有更新都已完成。 VB6与SP6。

我试图枚举的密钥肯定存在。但是,在新VM上我收到错误87 - "参数不正确",当调用RegQueryInfoKey时。

Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryInfoKey Lib "advapi32.dll" Alias "RegQueryInfoKeyA" (ByVal hKey As Long, ByVal lpClass As String, lpcbClass As Long, ByVal lpReserved As Long, lpcSubKeys As Long, lpcbMaxSubKeyLen As Long, lpcbMaxClassLen As Long, lpcValues As Long, lpcbMaxValueNameLen As Long, lpcbMaxValueLen As Long, lpcbSecurityDescriptor As Long, lpftLastWriteTime As Any) As Long


Private Sub Command1_Click()
    Dim lResult As Long
    Dim hKey    As Long
    Dim cJunk As Long
    Dim cNameMax As Long
    Dim ft As Currency

    lResult = RegOpenKeyEx(&H80000001, "Software\Speedocs\[...]", 0, &H1, hKey)
    If (lResult = ERROR_SUCCESS) Then
        MsgBox RegQueryInfoKey(hKey, "", cJunk, 0, cJunk, cJunk, cJunk, cJunk, cNameMax, cJunk, cJunk, ft)
    End If
End Sub

1 个答案:

答案 0 :(得分:1)

对于遇到此问题的任何人:问题是VB6用于兼容模式(专门用于Windows XP)。我在Windows 7机器上运行VB6。我记得在某处读取VB6必须在兼容模式下使用,因此将其设置为Windows XP兼容性。一旦我取消选中兼容模式,问题就解决了。