Writing hex value to registry

Hello,
my Xojo application has to write some entries to the Windows registry so that a special scanner application has the correct values set (without user interaction) for scanning. I exported the correct registry entries with regedit.exe and opened the exported file with a text editor.

Some entries I need to write with the Xojo app to the registry look like this:

[HKEY_CURRENT_USER\\Software\\TheSpecialScannerSoftware] "NORMALDIALOG"=hex:2c,00,00,00,00,00,00,00,01,00,00,00,ff,ff,ff,ff,ff,ff,ff,ff,\\ ff,ff,ff,ff,ff,ff,ff,ff,4e,01,00,00,7a,01,00,00,38,02,00,00,56,02,00,00

In Xojo I would write:

reg = new RegistryItem("HKEY_CURRENT_USER\\Software\\TheSpecialScannerSoftware", TRUE) reg.Value("NORMALDIALOG") = ???
But what do I write where the questionmarks are?

Ok, maybe I found something which could answer my question here:
http://forums.realsoftware.com/viewtopic.php?f=6&t=1315&hilit=registry+hex%3A

Thankfully the old forums are still available :slight_smile:

Hi Christian,

I am guessing that the NORMALDIALOG is to be a REG_SZ string? If so, here is the code to create ‘TheSpecialScannerSoftware’, add the ‘NORMALDIALOG’ name, and set the string value to “hex:2c,00,00,00,00,00,00,00,01,00,00,00,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,4e,01,00,00,7a,01,00,00,38,02,00,00,56,02,00,00”

[code] Dim Reg, MyNewReg as RegistryItem
reg = New RegistryItem("HKEY_CURRENT_USER\SOFTWARE",True)
MyNewReg=reg.AddFolder(“TheSpecialScannerSoftware”)

MyNewReg.Value(“NORMALDIALOG”) = “hex:2c,00,00,00,00,00,00,00,01,00,00,00,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,ff,4e,01,00,00,7a,01,00,00,38,02,00,00,56,02,00,00”[/code]

Hello Eugene,
thanks for your reply. I will try your suggestion tomorrow at work, when I can use windows PC. The NORMALDIALOG value is shown as REG_BINARY in the registry editor.

In the meantime I tried to convert the string into a memory block (lets say myMemoryBlockFromString) as explained in the thread from the old forum, but the value does not get written to the registry. So this code does not do anything:

MyNewReg.Value("NORMALDIALOG") = myMemoryBlockFromString

I can write REG_DWORD and REG_SZ values without problem like:

MyNewReg.Value("jpeg_Comp") = 75 MyNewReg.Value("driv_sdpi") ="300 dpi"

Hi Christian,

Thanks for helping me understand that this is not a string. The beginning portion of "hex:2c,… made me believe this was to be a string.

Here is the code to create a REG_BINARY value in hexadecimal form:

[code] Dim Reg, MyNewReg as RegistryItem
reg = New RegistryItem(“HKEY_CURRENT_USER\SOFTWARE”,True)
MyNewReg=reg.AddFolder(“TheSpecialScannerSoftware”)

//MyNewReg.Value(“NORMALDIALOG”) = “2c 00 00 ff…”

Dim mb as new MemoryBlock(32) //each hexadecimal value has a length of 8 (8x4=32)
mb.Long(0) = &h2c //1 = 8
mb.Long(1) = &h00 //2 = 16
mb.Long(2) = &h00 //3 = 24
mb.Long(3) = &hff //4 = 32
//Keep going :slight_smile:
MyNewReg.Value(“NORMALDIALOG”) =mb[/code]

Happy to help

Hello Eugene,
thank you very much for your help, I got it to work now.
After getting your solution to work I also discovered a stupid mistake I made when trying the solution from the old forums. So now, both solution seem to work.

This is a simplified example how I do it now:

dim theString as String theString = "2c,00,00,00,00,00,00,00,01,00,00,00,ff...."

First I clean the string from all unvanted characters like „\“, and spaces and linebreaks.
theString = Replaceall(theString, “”, “”) …

dim reg as RegistryItem reg = new RegistryItem("HKEY_CURRENT_USER\\Software\\TheSpecialScannerSoftware", TRUE) reg.Value("NORMALDIALOG") = StringToMemoryBlock_Convert(theString)

The method StringToMemoryBlock_Convert looks like this:

[code]Function StringToMemoryBlock_Convert(theString as String) As MemoryBlock

dim i As Integer
dim maxI As Integer
dim arrayFromString() As String

arrayFromString = Split(theString, “,”)
maxI = UBound(arrayFromString)

dim mb As new MemoryBlock(maxI+1)

for i = 0 to maxI
mb.Byte(i) = val("&h" + arrayFromString(i))
Next

Return(mb)

End Function[/code]

Or the other way:

[code]Function StringToMemoryBlock_Convert(theString as String) As MemoryBlock

dim i As Integer
dim maxI As Integer
dim arrayFromString() As String

arrayFromString = Split(theString, “,”)
maxI = UBound(arrayFromString)

dim mb As new MemoryBlock((maxI+1) * 8)

for i = 0 to maxI
mb.Long(i) = val("&h" + arrayFromString(i))
Next

Return(mb)

End Function[/code]