Link to home
Start Free TrialLog in
Avatar of kaima
kaima

asked on

Reading the Registry using VB6

Hi,

I need to read from the registry using VB6. I have tried using GetSetting function but that did not help.
For example I need to read the value of the key HKEY_LOCAL_MACHINE\SOFTWARE\XXXSOFT\XYZSOFT_HOME

Any help is welcome

Thanks...
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RonPierce
RonPierce

The posting from dhaest on reading the registry in VB is the ONLY one I have found that actually works!  SO, I am curious as to why it is necessary to Dim a Byte array as  the receiving area for the registry key? It DOES seem to be necessary, for if I specify a String variable (adequately sized by Stringvar = String(1024,0) for example), the call to RegQueryValueEx  fails in my WORD/VBA macro (Office 2000), crashing WORD every time ("An error log has been created" --- sez Windows 2000, but it's nowhere to be found, of course; Win98 indicates an invalid operation, suggesting a write-protection fault).   In my case, I know that the key value is a REG_SZ, and in fact, a call to RegQueryValueEx with a null 'lpData' returns the data type as REG_SZ  and returns the required buffer size (verified as correct, by looking at the Registry) --- BUT when I then pass the String variable as the 'lpData' --- CRASH, every time.  Why?  Clearly, there are things about the "inner" workings of VB/VBA that I do not understand.  I'm feeling very fortunate to have found this posting after days of frustration, so I would welcome an explanation as to why a String var cannot be used --- or what it takes to use one in a "acceptable" way!
My recommandation: answered by dhaest
Private Sub Form1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Dim KeyVal As String
    KeyVal = GetSetting(Application.Name, "HKEY_LOCAL_MACHINE\SOFTWARE\XXXSOFT\", "XYZSOFT_HOME", "")
End Sub
I found Dhaest's code solution to be Extremely Helpful.