i want to set this to read from the "cd Quality" key

anyone help me ?
ive tried changing key2, "Cd Quality", with no luck ! where am i going wrong ?

Private Function GetDefaultWaveFormat(format As WAVEFORMAT) As Boolean
'////////////////////////////////////////////////////////////////////////////////////
' This user-defined function retrieves the default wave format from the registry.
'////////////////////////////////////////////////////////////////////////////////////
Dim rc As Long
Dim key1 As Long
Dim key2 As Long
Dim formatName As String * 50
Dim length As Long

' Initialize return code
GetDefaultWaveFormat = False

rc = RegOpenKeyEx(HKEY_CURRENT_USER, _
"Software\Microsoft\Multimedia\Audio", _
0, _
KEY_READ, _
key1)
If (rc <> 0) Then
Exit Function
End If

length = Len(formatName)
rc = RegQueryValueString(key1, "DefaultFormat", 0, 0, formatName, length)

If (NO_ERROR = rc) Then
rc = RegOpenKeyEx(HKEY_CURRENT_USER, _
"Software\Microsoft\Multimedia\Audio\WaveFormats", _
0, _
KEY_READ, _
key2)

If (NO_ERROR = rc) Then
length = Len(format)
rc = RegQueryValueEx(key2, _
formatName, _
0, _
0, _
format, _
length)
RegCloseKey key2

If (NO_ERROR = rc) Then
GetDefaultWaveFormat = True
End If
End If
End If
RegCloseKey key1
End Function

Recommended Answers

All 6 Replies

I know there is a GetSettings and SaveSettings function in VB. Perhaps you can look into them and pass parameters as to which registry needs to be altered (SaveSettings).

I know that the API is a fun place to play around, but you should really consider using windows scripting for that task....

dim NewValue as string
dim WSH
set WSH = createobject("WScript.Shell")
NewValue = "Whatever you want CD Quality's Value To Be"

WSH.regwrite "HKEY_CURRENT_USER\Software\Microsoft\Multimedia\Audio\WaveFormats\CD Quality", NewValue, "REG_SZ"

set WSH = nothing

Post Edit: Sorry, I was reading it in a hurry, the CD Quality's key is NOT a string (REG_SZ), it's a binary or Hex... I'll keep digging around and let you know what I find.

Member Avatar for AlanC

I honestly don't know. It rattled my cage when I tried all of the registry access methods I knew! I then tried the sRegistry class from: http://www.vbaccelerator.com/home/VB/Code/Libraries/Registry_and_Ini_Files/Complete_Registry_Control/article.asp

which does the trick... you'll have to download the class module and add it to your project.

I dropped a list box and a command button on the form and [eventually] sussed out that the returned value is a 16-byte long byte array which you can then convert into something useful.

The code here for the button enumerates the keys in /.../WaveFormats and displays the value of each in the same format as Regedit. Presumably you could then do maths on them to get 44100 16 bit etc.

Private Sub Command1_Click()
    Dim c As New cRegistry
    Dim sKeys() As String, iKeyCount As Long
    Dim ikey As Long
    Dim ibyte As Long
    Dim vr As Variant
    Dim sOut As String
    Dim sTemp As String
    With c
        .ClassKey = HKEY_CURRENT_USER
        .SectionKey = "Software\Microsoft\Multimedia\Audio\WaveFormats"
        ret = .EnumerateValues(sKeys(), iKeyCount)
        For ikey = 1 To iKeyCount
            Debug.Print sKeys(ikey)
            .ValueKey = sKeys(ikey)
            .ValueType = REG_BINARY
            vr = .Value
            'read bytes in the byte array and assemble into human-readable form
            sOut = ""
            For ibyte = LBound(vr) To UBound(vr)
               sTemp = Hex$(vr(ibyte))
               If Len(sTemp) = 1 Then sTemp = "0" & sTemp
               sOut = sOut & sTemp & " "
            Next ibyte
            'write to the list box
            List1.AddItem sKeys(ikey) & ":" & sOut

        Next ikey
    End With
End Sub

I hope you can interpret what this returns!!

I still think there's a simpler way and that may be to initialise the sound card using waveindevcaps api and then read the formats if that's possible. In the absence of anything else, the default values should be returned.

Hope this helps

AlanC

Member Avatar for AlanC

OK moderator, what did I do wrong with the code?
How can I get the image to be embedded?

I think it needs a full url

Member Avatar for AlanC

Thanks, Comatose
Rgds
AlanC

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.