Results 1 to 5 of 5

Thread: Saving REG_BINARY values

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    39

    Saving REG_BINARY values

    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.




  2. #2
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613
    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

  3. #3
    jim mcnamara
    Guest
    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
    If you declare the lpData parameter as String, you must pass it By Value. This will pass your string of hex values.

    Create a new declaration like the one above
    Call RegSetValueExString(.....)


  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    39
    Thanks for your suggestions,

    If you declare the lpData parameter as String, you must pass it By Value. This will pass your string of hex values.
    This works, but since VB stores strings as Unicode, I have trayling zeros at the end of every value, such as:
    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?

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    39

    StrConv

    Never mind,

    Just remembered about StrConv to convert from Unicode, and it worked just great.

    Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width