Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems reading from registry

Status
Not open for further replies.

snerting

Programmer
Oct 20, 2005
52
I'm using a registry setting to control how the access app should read data. The registry setting is controlled by another application. However, at some random intervals, the data read from registry is bugus. It seems to be a collection of spaces and line breaks, while the string in registry really is something else. If I run regedit and just double click the setting in question (without chanting anything), access will read it fine again.

The code:

Dim lResult As Long
Dim lKeyValue As Long
Dim sValue As String
Dim lValueLength As Long
Dim lDataTypeValue As Long

sValue = Space$(2048)
lValueLength = Len(sValue)

lResult = RegOpenKey(dataset.HKEY_CURRENT_USER, "software\\Foo\\bar", lKeyValue)
lResult = RegQueryValueEx(lKeyValue, "foobar", 0&, lDataTypeValue, sValue, lValueLength)
sValue = Left$(sValue, lValueLength - 1)


Any ideas on why this is happening?
 
Are you calling RegCloseKey afterwards?

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Nop, I'll try that and see how it turns out. After all, this problem is only surfacing once and a while.
 
chiph: I tried RegCloseKey but it didn't fix the problem. The application is actually polling this registry setting frequently (through a timer *yack*), but it actually seems like the problem surfaces when there is a substantial time since last time the application was run.
 
Since the original writers of the code weren't calling RegCloseKey(), I suspect there are other pieces of code that have poor resource cleanup being done. I would look around at related code to make sure files are being closed, handles freed, etc.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Timer, eh? You might want to look at the RegNotifyChangeKeyValue notification (not that this will fix your current problem, but it beats polling as a technique)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top