为模块Module1编写子过程Main(),其功能为调用API函数RegQueryValue读取Windows
登录数据库( Registry)中HKEY_CLASSES_ROOT.txt键的默认值.

解决方案 »

  1.   

    试试...
    Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As String, vValue As Variant) As Long
          Dim cch As Long
          Dim lrc As Long
          Dim lType As Long
          Dim lValue As Long
          Dim sValue As String
          
          On Error GoTo QueryValueExError
          
          lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
          If lrc <> ERROR_NONE Then Error 5
          
          
          Select Case lType
               Case REG_SZ:
                   sValue = String(cch, 0)
                   lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
                   If lrc = ERROR_NONE Then
                         vValue = Left$(sValue, cch)
                   Else
                         vValue = Empty
                   End If
            
               Case REG_DWORD
                   lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch)
                   If lrc = ERROR_NONE Then vValue = lValue
               Case Else
                   lrc = -1
          End Select
          
    QueryValueExExit:
          
          
          QueryValuEx = lrc
          Exit Function
          
          
    QueryValueExError:      Resume QueryValueExExitEnd Function