Problem writing byte array to file

In windows, when Evernote is installed, api is also installed, which can be accessed via vba (for example).

Each note can display “Resources” (attached files and images), and actual resources can be obtained as arrays of bytes.

I'm having trouble writing byte arrays to the actual file.

Variable declaration:

Dim fileByte() As Byte
Dim nt As enapiLib.Note

Extract data:

fileByte = nt.Resources.Item(i).Data

Writing a byte array to a file:

Function WriteByteArray(vData As Variant, sFileName As String, Optional bAppendToFile As Boolean = False) As Boolean
Dim iFileNum As Integer, lWritePos As Long

Debug.Print " --> Entering WriteByteArray function with " & sFileName & " file to write."
On Error GoTo ErrFailed
If bAppendToFile = False Then
    If Len(Dir$(sFileName)) > 0 And Len(sFileName) > 0 Then
        'Delete the existing file
        VBA.Kill sFileName
    End If
End If

iFileNum = FreeFile
Debug.Print "iFileNum = " & iFileNum
'Open sFileName For Binary Access Write As #iFileNum
Open sFileName For Binary Lock Read Write As #iFileNum

If bAppendToFile = False Then
    'Write to first byte
    lWritePos = 1
Else
    'Write to last byte + 1
    lWritePos = LOF(iFileNum) + 1
End If

Put #iFileNum, lWritePos, vData
Close #iFileNum

WriteByteArray = True
Exit Function

ErrFailed:
Debug.Print "################################"
Debug.Print "Error handling of WriteByteArray"
Debug.Print "################################"
FileWriteBinary = False
Close iFileNum
Debug.Print Err.Description & "(" & Err.Number & ")"
End Function

I tried with exe file

Debugging every byte value, I know that my byte starts with 4D 5A, like any other exe file

Resource (1) : 
ClickToSetup.0.9.8.1416.exe
application/x-msdownload
Le fichier C:\Dropbox\TestEvernote\ClickToSetup.0.9.8.1416.exe doit être créé.
Lbound(fileByte) = 0
Ubound(fileByte) = 5551919
i = 0
filebyte(i) = 4D
i = 1
filebyte(i) = 5A

When reading an exe file created in an array of bytes, I know that a newly created array starts with byte 4D 5A as desired

exe , , _corrupted_, _ _ :

: ( VBinDiff) ( , ...): VBinDiff exe

12 ?

+5
2

- 12- . , PUT , Variant. , , PUT:

    Put #iFileNum, lWritePos, vData

:

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

.

+10

VB6, 12 , . ? Variant, Variant.

"" Variant Byte, :

ReDim arrByte(UBound(varBuffer))

For i = 0 To UBound(varBuffer)
  arrByte = varBuffer(i)
Next i
0

All Articles