-
reading hex-values from registry
Hi there!
Once again I'm in need of professional skill:
I want to read a value from the registry. This value is in hex. For example
the value '300.000' is displayed as '0x000493e0' (and stored as '000493e0').
No problem so far, but when I read this value from my vb-app, I receive the
value 'à“' (= crap).
I changed the value to 34343434 ('cause 34 in hex is '4' in ASCII) and I
received '4444' (just as I expected).
So, here is the problem:
Why does the code (typed below) read each single byte from the registry-value
and convert it as if it was an ASCII code??
And how to fix??
Here's the code I used:
...
rc = RegOpenKeyEx(&H80000002, pathName(i), 0, &H1, hKey)
If rc = 0 Then
rc = RegQueryInfoKey(hKey, 0, 0, 0, 0, 0, 0, 0, 0, ValueLen, 0, 0)
ValueLen = ValueLen + 1
ValueData = Space(ValueLen)
rc = RegQueryValueEx(hKey, ValueName, 0, REG_BINARY, ByVal ValueData,
ValueLen)
Select Case ValueType
Case 1, 2, 7:
ValueLen = ValueLen - 1
End Select
lblMax(i).Caption = Left(ValueData, ValueLen)
rc = RegCloseKey(hKey)
...
Instead of REG_BINARY I also used REG_DWORD, REG_SZ, REG_NONE, REG_DWORD_BIG_ENDIAN,
REG_EXPAND_SZ and REG_MULTI_SZ, but nothing seemed to work.
Now, have a go!!
10 print "Thank you"
20 goto 10
;-)
-
Re: reading hex-values from registry
> I want to read a value from the registry. This value is in hex. For example
> the value '300.000' is displayed as '0x000493e0' (and stored as '000493e0').
> No problem so far, but when I read this value from my vb-app, I receive the
> value 'à"' (= crap).
> I changed the value to 34343434 ('cause 34 in hex is '4' in ASCII) and I
> received '4444' (just as I expected).
>
> So, here is the problem:
> Why does the code (typed below) read each single byte from the registry-value
> and convert it as if it was an ASCII code??
> And how to fix??
>
> Here's the code I used:
>
> ..
> rc = RegOpenKeyEx(&H80000002, pathName(i), 0, &H1, hKey)
>
> If rc = 0 Then
> rc = RegQueryInfoKey(hKey, 0, 0, 0, 0, 0, 0, 0, 0, ValueLen, 0, 0)
> ValueLen = ValueLen + 1
> ValueData = Space(ValueLen)
> rc = RegQueryValueEx(hKey, ValueName, 0, REG_BINARY, ByVal ValueData,
> ValueLen)
> Select Case ValueType
> Case 1, 2, 7:
> ValueLen = ValueLen - 1
> End Select
> lblMax(i).Caption = Left(ValueData, ValueLen)
> rc = RegCloseKey(hKey)
> ..
>
> Instead of REG_BINARY I also used REG_DWORD, REG_SZ, REG_NONE, REG_DWORD_BIG_ENDIAN,
> REG_EXPAND_SZ and REG_MULTI_SZ, but nothing seemed to work.
What is ValueData defined as? Try defining as a long. The data is being copied directly into the string and then being interpreted
as ASCII data. If this doens't work, It may be due to it expecting a pointer so try byref ValueData.
> 10 print "Thank you"
> 20 goto 10
Goto has been depreciated )
Sub ThankYou()
Print "Thank you"
ThankYou()
End Sub
)
/me waits for stack overflow
--
Dean Earley (dean.earley@icode.co.uk)
Assistant Developer
iCode Systems
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|