0

I have been using GetValue with GetValueKind and have just come across an issue when Reading DWORD that is larger than the signed 32-bit integer. I am able to Write to to the registry without restriction, getting to the max of 4294967295 (ffffffff in hex).

If there was a way to do this with int64 then I wouldnt be restricted..

I could make this work if I could read the hexadecimal value, which i could just convert to decimal via int64, though again, I dont know how i would read the hex value from the registry..

Is there another route I should take to allow me to Read the correct value when it exceeds the signed 32-bit integer value of 2,147,483,647?

thanks

qsNeedAs
  • 1
  • 3
  • Does it not just wrap around to Integer.MinValue ? i.e. you write -1 and end up with 0xffffffff or, you write -2,147,483,648 and end up with 0x80000000 – Caius Jard Jul 15 '21 at 11:48
  • 2
    How about you start by showing us the actual code you're using now? ALWAYS provide the relevant code. – jmcilhinney Jul 15 '21 at 12:04
  • @CaiusJard I see the results and how youre right about that, but not sure how that i could use that information – qsNeedAs Jul 15 '21 at 20:18
  • What I'm saying is that a signed integer and an unsigned integer are the same thing; if you set your value to 0xfffffffe in regedit then it will say it's 4294967294, and if you read it in .net it will say it's -2, because unsigned 4294967295 = -2 signed. None of it needs to go through int64, you just need to understand that e.g. -1, 4294967295 and 0xffffffff are all the same thing. If you use .net to write -3, your regedit will show 4294967293 or 0xfffffffd. int goes from 0 to 2,147,483,647 (0x7fffff) then if you add 1 to it it becomes -2,147,483,648 (as an int) or 2,147,483,648 as a uint – Caius Jard Jul 15 '21 at 21:01
  • @CaiusJard I appreciate your input, quite helpful in regards to understanding the units. – qsNeedAs Jul 15 '21 at 21:26

2 Answers2

0

DWORD is a 32-bit unsigned integer - not a signed integer, so use UInt32 instead.

According to 2.2.9 DWORD

A DWORD is a 32-bit unsigned integer (range: 0 through 4294967295 decimal). Because a DWORD is unsigned, its first bit (Most Significant Bit (MSB)) is not reserved for signing.

Data Type Summary (Visual Basic)

enter image description here enter image description here

Resources:

Tu deschizi eu inchid
  • 4,117
  • 3
  • 13
  • 24
  • Thanks for your response, though I was getting at the fact that the function GetValue, uses signed integers. I am unable to get the value to Unsigned with my current code. Textbox1.text = Registry.CurrentUser.OpenSubKey(PATH, False).GetValue(NAME) – qsNeedAs Jul 15 '21 at 20:13
  • @user9938 your DataType Summary is right, but it's misleading. It would perhaps be more helpful to say "int goes from 0 to 2,147,483,647 then -2,147,483,648 to -1"; go into project properties advanced compile and turn off overflow checks and set an int to int.MaxValue. Then add 1 to it; it's now int.MinValue – Caius Jard Jul 15 '21 at 21:08
  • @CaiusJard awesome thanks for your input dude. I did manage to figure it out by getting the bytes first, then converting it from there. I posted what worked for me above – qsNeedAs Jul 15 '21 at 21:22
0
Dim PATH as string = "HKEY_CURRENT_USER\Software\Test"
Dim NAME as string = "TestName"
Dim ft As String = "DOES_NOT_EXIST"
Dim gv As Object = Registry.GetValue(PATH, NAME, ft)
Dim gb As Byte() = BitConverter.GetBytes(CInt(gv))
Dim j As UInt32 = BitConverter.ToUInt32(gb, 0)
Textbox1.text = j
qsNeedAs
  • 1
  • 3