×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Problems reading from registry

Problems reading from registry

Problems reading from registry

(OP)
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?

RE: Problems reading from registry

Are you calling RegCloseKey afterwards?

Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first

RE: Problems reading from registry

(OP)
Nop, I'll try that and see how it turns out. After all, this problem is only surfacing once and a while.

RE: Problems reading from registry

(OP)
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.

RE: Problems reading from registry

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

RE: Problems reading from registry

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)

RE: Problems reading from registry

>RegNotifyChangeKeyValue

See thread711-730276.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close