Public Function getQqPath2() As String  '可以查出注册表的值为“TencentProtocol”
   
Dim ret, lenData, hKey As Long
Dim sValue As String
Dim name As String
   
    sValue = Space(255)
    Const REG_SZ = 1&
   
    lenData = 255
    
    name = ""
    ret = 1
    ret = RegOpenKey(HKEY_CLASSES_ROOT, "Tencent", hKey)
    If ret = 0 Then
        ret = RegQueryValueEx(hKey, name, 0, REG_SZ, ByVal sValue, lenData)
        ret = InStr(1, sValue, "Protocol")
        getQqPath2 = Left(sValue, ret + 10)
    End If
    ret = RegCloseKey(hKey)
    
End FunctionPrivate Sub Command1_Click()
If getQqPath2 = "TencentProtocol" Then  '明明值就是“TencentProtocol”,但是总判断为not,我不知道哪里出错了?



解决方案 »

  1.   

    Option Explicit
    Private Const HKEY_CLASSES_ROOT = &H80000000
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As LongPrivate Function getQqPath2() As String  '可以查出注册表的值为“TencentProtocol”
            
        Dim ret As Long, lenData As Long, hKey As Long
        Dim sValue As String
        Dim name As String
        
        sValue = Space(255)
        Const REG_SZ = 1&
        
        lenData = 255
         
        name = ""
        ret = 1
        ret = RegOpenKey(HKEY_CLASSES_ROOT, "Tencent", hKey)
        If ret = 0 Then
            ret = RegQueryValueEx(hKey, name, 0, REG_SZ, ByVal sValue, lenData)
            ret = InStr(1, sValue, Chr$(0))
            getQqPath2 = Mid(sValue, 1, ret - 1)
        End If
        ret = RegCloseKey(hKey)
         
    End FunctionPrivate Sub Command1_Click()
        If getQqPath2 = "TencentProtocol" Then
            Debug.Print "equ"
        Else
            Debug.Print "not equ"
        End If
    End Sub