Hello,
How can I save a REG_BINARY value using RegSetValueEx if the value is more than Long type can handle, for instance:
02 05 20 A5 F8 56 12 45 F9 C3, etc...
I can't pass it as a string, always get an error.
Any help is appreciated.
:confused:
Printable View
Hello,
How can I save a REG_BINARY value using RegSetValueEx if the value is more than Long type can handle, for instance:
02 05 20 A5 F8 56 12 45 F9 C3, etc...
I can't pass it as a string, always get an error.
Any help is appreciated.
:confused:
Code:Public Sub SaveSettingByte(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String, byData() As Byte)
Dim lRegResult As Long
Dim hCurKey As Long
lRegResult = RegCreateKey(hKey, strPath, hCurKey)
lRegResult = RegSetValueEx(hCurKey, strValueName, 0&, REG_BINARY, byData(0), UBound(byData()) + 1)
lRegResult = RegCloseKey(hCurKey)
End Sub
If you declare the lpData parameter as String, you must pass it By Value. This will pass your string of hex values.Code:Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName _
As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Create a new declaration like the one above
Call RegSetValueExString(.....)
:)
Thanks for your suggestions,
This works, but since VB stores strings as Unicode, I have trayling zeros at the end of every value, such as:Quote:
If you declare the lpData parameter as String, you must pass it By Value. This will pass your string of hex values.
02 00 05 00 20 00 A5 00 F8 00 56 00 12 00 45 00 F9 00 C3 00
Is there way around it?
Never mind,
Just remembered about StrConv to convert from Unicode, and it worked just great.
Thank you very much.