frodo Posted February 27, 2008 Posted February 27, 2008 (edited) Okay, this is really annoying me, and im struggling to figure it out. The problem is with Hex(), i need to get the return from the regread (returns the decimal value) and convert it to hex, why i cant choose to have the DWORD key type in Hex by default, i dont know, but there you are..... For example: $1 = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation", "ActiveTimeBias") MsgBox(0,"test1", $1) This returns: 4294966636 (Correct) $result = Hex($1) MsgBox(0,"test2", $result) This returns: 8000000 (Incorrect) While specifying: $result2 = Hex(4294966636) MsgBox(0,"test3", $result2) Returns: FFFFFD6C (Correct) What am i missing here? Edited February 27, 2008 by frodo
weaponx Posted February 27, 2008 Posted February 27, 2008 RegRead is probably retrieving a string datatype, simply convert it. $1 = "4294966636" $result = Hex(Number($1)) MsgBox(0,"test2", $result)
frodo Posted February 27, 2008 Author Posted February 27, 2008 (edited) RegRead is probably retrieving a string datatype, simply convert it. $1 = "4294966636" $result = Hex(Number($1)) MsgBox(0,"test2", $result) Id love to tell you that worked, but i already tried anything i could in the helpfile at 1:00AM including IsInt() and IsNumber() (both return 1 btw) etc...makes no difference Number() is not the solution. Surely RegRead knows its a DWord value as i can confiirm it with the @extended value.... Why it comes back as Decimal as default is really quite pissing me off Anyways heres the original code in one hit, updated the msgbox headnigs form test 1 etc to make it easier to see which value is being displayed $1 = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation", "ActiveTimeBias") MsgBox(0,"RegRead - Decimal ", $1) $result = Hex($1) MsgBox(0,"Hex", $result) $result2 = Hex(4294966636) MsgBox(0,"Correct Hex", $result2) A big thank you to the first person who can figure out why this isnt working Edited February 27, 2008 by frodo
weaponx Posted February 27, 2008 Posted February 27, 2008 I don't see the problem. I opened that key in regedit and heres what it shows: 0x0000012c (300) $1 = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation", "ActiveTimeBias") MsgBox(0,"test1", $1) ;Shows "300" $result = Hex($1) MsgBox(0,"test2", $result) ;Shows "12c" Works fine.
frodo Posted February 27, 2008 Author Posted February 27, 2008 (edited) I don't see the problem. I opened that key in regedit and heres what it shows: 0x0000012c (300) $1 = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation", "ActiveTimeBias") MsgBox(0,"test1", $1) ;Shows "300" $result = Hex($1) MsgBox(0,"test2", $result) ;Shows "12c" Works fine. Again, i know youre trying to help, but im seriously not joking, even cutting and pasting your example equals failure for me: I get: 4294966636 which as previously stated is whats in the registry and 1000% correct And : 80000000 after Hex() Total failure......somewhere deep in the bowels of AutoIT, something is p4uck3d, this is ridiculous.... What im doing in writing a routine that regreads values from the registry and depending on the @extended value, writes the keys with a correct prefix and format for use in BartPE .inf files... And before you ask why im not reg exporting it all, i need to manipulate the data before writing it out Sheesh, even doing the binary 0x3 type stuff (inserting commas every 3 characters and backslashes and @CRLF at every 63rd) was simple compared to my current drama.... For example (chopped a lot out for brevity): $1 = RegReadExt("HKLM\SYSTEM\ControlSet001\Services\IdeBusDr\Security", "Security") IniWrite($IniFile, "Setup.AddReg", $RegTypePrefix & ', "CurrentControlSet\Services\IdeBusDr\Security"' & ", " & $ValueNameFinal & $ValueFinal, "IGNORE") $2 = RegReadExt("HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation", "ActiveTimeBias") IniWrite($IniFile, "Setup.AddReg", $RegTypePrefix & ', "CurrentControlSet\Control\TimeZoneInformation"' & ", " & $ValueNameFinal & $ValueFinal, "IGNORE") Func RegReadExt($MainKey, $ValueName) $ValueReturn = RegRead($MainKey, $ValueName) Select Case @extended = 3 $RegTypePrefix = "0x3" $ProcValue1 = _StringInsert2($ValueReturn, ",", 2); external routine that inserts characters every x chars. This time its the commas between number pairs $ProcValue2 = _StringInsert2($ProcValue1, "\" & @CRLF, 63 );backslash and line breaks at every 63rd character, 63 looks pretty $ValueName = Chr(34) & $ValueName & Chr(34) $ValueFinal = @CRLF & $ProcValue2 & @CRLF Case @extended = 4 $RegTypePrefix = "0x4" $ValueName = $ValueName $ValueFinal = "0x" & Hex($ValueReturn) EndSelect EndFunc Which gives output like: [Setup.AddReg] 0x3, "CurrentControlSet\Services\IdeBusDr\Security", "Security",\ 01,00,14,80,90,00,00,00,9C,00,00,00,14,00,00,00,30,00,00,00,02,\ 00,1C,00,01,00,00,00,02,80,14,00,FF,01,0F,00,01,01,00,00,00,00,\ 00,01,00,00,00,00,02,00,60,00,04,00,00,00,00,00,14,00,FD,01,02,\ 00,01,01,00,00,00,00,00,05,12,00,00,00,00,00,18,00,FF,01,0F,00,\ 01,02,00,00,00,00,00,05,20,00,00,00,20,02,00,00,00,00,14,00,8D,\ 01,02,00,01,01,00,00,00,00,00,05,0B,00,00,00,00,00,18,00,FD,01,\ 02,00,01,02,00,00,00,00,00,05,20,00,00,00,23,02,00,00,01,01,00,\ 00,00,00,00,05,12,00,00,00,01,01,00,00,00,00,00,05,12,00,00,00 0x4, "CurrentControlSet\Control\TimeZoneInformation", "ActiveTimeBias", 0x80000000 Edited February 27, 2008 by frodo
Siao Posted February 27, 2008 Posted February 27, 2008 (edited) I feel you, AutoIt's variable types and their conversions had me lose a lot of hair too, it's easily the weakest and most annoying thing about this scripting language. Anyway, the problem is that returned integer is unsigned, and Hex() can't convert those. Hex(Int($1)) did the trick for me. Edited February 27, 2008 by Siao "be smart, drink your wine"
frodo Posted February 27, 2008 Author Posted February 27, 2008 I feel you, AutoIt's variable types and their conversions had me lose a lot of hair too, it's easily the weakest and most annoying thing about this scripting language.Anyway, the problem is that returned integer is unsigned, and Hex() can't convert those.Hex(Int($1))did the trick for me.You dear Sir, are a prince amongst men.Thank you very much.I dont know why i didnt try that in amongst the half million things i tried before posting.Just quietly, this whole thing is quite retarded
weaponx Posted February 27, 2008 Posted February 27, 2008 It says right in the help file for Hex():The function only works with numbers that fit in a 32 bit signed integer (-2147483648 to 2147483647)
Siao Posted February 27, 2008 Posted February 27, 2008 (edited) It says right in the help file for Hex():"The function only works with numbers that fit in a 32 bit signed integer (-2147483648 to 2147483647)"That it does, but that can be interpreted differently.It can mean that $x must be in the range -2147483648 to 2147483647, but that wouldn't be consistent with the perceived reality which OP demonstrated - Hex(4294966636) works just fine.It can mean that $x must be Int32, and unsigned 4294966636 technically "fits" in a 32 bit signed integer (both take 4 bytes) so it should work.But then the puzzling question is why Hex($1) doesn't work, especially considering that IsInt($1) reports "True" (VarGetType reports "Double" though).So for average AutoIt user who doesn't know the internals, all this "variable" or "variant" type shmuckery is puzzling, to say the least. I know it was for me (and still is sometimes, I find myself having to resort to trial-and-error method more often than I would like). Most of the time you don't even notice and enjoy the fact how AutoIt automagically converts types for you, but then you need to do something specific and hit the wall. Edited February 27, 2008 by Siao "be smart, drink your wine"
frodo Posted February 28, 2008 Author Posted February 28, 2008 That it does, but that can be interpreted differently.It can mean that $x must be in the range -2147483648 to 2147483647, but that wouldn't be consistent with the perceived reality which OP demonstrated - Hex(4294966636) works just fine.It can mean that $x must be Int32, and unsigned 4294966636 technically "fits" in a 32 bit signed integer (both take 4 bytes) so it should work.But then the puzzling question is why Hex($1) doesn't work, especially considering that IsInt($1) reports "True" (VarGetType reports "Double" though).So for average AutoIt user who doesn't know the internals, all this "variable" or "variant" type shmuckery is puzzling, to say the least. I know it was for me (and still is sometimes, I find myself having to resort to trial-and-error method more often than I would like). Most of the time you don't even notice and enjoy the fact how AutoIt automagically converts types for you, but then you need to do something specific and hit the wall.Exactly right.Very eloquently put, i couldnt have put i better myselfThe very first thing i tried was: IsInt($1) to make sure i was complying with the Hex() function........dont shoot the end user, i was merely following instructions in the help file. The demon is not me, the demon is in the code.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now