Can anyone see what's wrong with this code? I'm attempting to parse available Windows Updates, but although I can list the updates (or what I believe to be the updates), it crashes at the end on freeing the memory used to store the Registry key name, and I can't see any good reason for it!
Code: Select all
EnableExplicit
Define subkeyname.s = "SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\ApplicabilityEvaluationCache"
Define key.i
If RegOpenKeyEx_ (#HKEY_LOCAL_MACHINE, @subkeyname, 0, #KEY_READ, @key) = #ERROR_SUCCESS
Define index.i = 0
Define size.i = 1024 ; Start value, will be increased on #ERROR_MORE_DATA in loop...
Define last.i
Define *subkey = AllocateMemory (size)
Define result.i
Define valuelength.i
Define keylength.i
Repeat
result = RegEnumKeyEx_ (key, index, *subkey, @size, #Null, #Null, #Null, @last)
Select result
Case #ERROR_SUCCESS
Debug PeekS (*subkey)
; Look through values for ApplicabilityState $112, CurrentState $0 = not installed
index = index + 1
Case #ERROR_MORE_DATA
; Get length of largest key name...
If RegQueryInfoKey_ (key, #Null, #Null, #Null, #Null, @keylength, #Null, #Null, @valuelength, #Null, #Null, #Null) = #ERROR_SUCCESS
; Debug size
; Debug keylength
; Debug valuelength
size = keylength + 1 ; Add null char
*subkey = ReAllocateMemory (*subkey, size)
Else
Debug "RegQueryInfoKey failed" ; Doesn't happen...
EndIf
Case #ERROR_NO_MORE_ITEMS
Break
Default
Debug "Something else!" ; Doesn't happen...
Break
EndSelect
ForEver
Debug "Freeing *subkey..."
FreeMemory (*subkey) ; *** CRASH! *** -- works if commented out
Debug "Closing Registry key..."
RegCloseKey_ (key)
Debug "Finished!"
EndIf
(BTW Anyone know why PB closes the Debug Output window on OK'ing "The debugged executable quit unexpectedly"? It makes it really hard to parse the output since you can't access the scrollbar while the dialog is open, but closing it closes Debug Output!)