Issue with writing byte array to a file

前端 未结 2 1650
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 10:05

Under windows, when Evernote is installed, an api is also installed, which can be accessed through vba (for example).

Each notes can show its \"Resources\" (attached

相关标签:
2条回答
  • 2021-01-18 10:47

    In VB6, there’s a mysterious extra 12 bytes prepended to the content that is saved. Why? Because you saved the Variant structure as well as the contents of the Variant.

    You need to "copy" the Variant content to Byte array, for example:

    ReDim arrByte(0 To UBound(varBuffer) - LBound(varBuffer))
    
    For i = 0 To UBound(varBuffer) - LBound(varBuffer)
      arrByte = varBuffer(i + LBound(varBuffer))
    Next i
    
    0 讨论(0)
  • 2021-01-18 10:49

    I had the same problem - some 12 byte header thrown at the top of every file written. It turns out that the PUT command doesn't quite know how to handle data of type Variant. I'm not sure of the exact cause, but my work around was to simply replace the PUT line:

        Put #iFileNum, lWritePos, vData
    

    with this:

        Dim buffer() As Byte
        buffer = vData
        Put #iFileNum, lWritePos, buffer
    

    Problem solved.

    0 讨论(0)
提交回复
热议问题