Не забывайте обнулять вещи, на которые вам наплевать:
#include once "windows.bi"
Type FileHeader
dwMagic As Long
dwVersion As Long
szComment As ZString * (255 + 1)
cbData As Long
End Type
Function SafeToFile( _
ByVal hFile As HANDLE, _
ByVal pszComment As ZString Ptr, _
ByVal cbData As Long, _
ByVal bData As UByte _
)As Integer
Dim fh As FileHeader Ptr = Allocate(SizeOf(FileHeader))
fh->dwMagic = 16
fh->dwVersion = 1
lstrcpyA(@fh->szComment, pszComment)
fh->cbData = cbData
Dim cbWritten As DWORD = Any
WriteFile(hFile, fh, SizeOf(FileHeader), @cbWritten, NULL)
WriteFile(hFile, @bData, SizeOf(UByte), @cbWritten, NULL)
Return 0
End Function
Dim hFile As HANDLE = CreateFileA( _
"file.bin", _
GENERIC_WRITE, _
0, _
NULL, _
CREATE_ALWAYS, _
FILE_ATTRIBUTE_NORMAL, _
NULL _
)
Const Comment = Str("this is a comment")
If hFile <> INVALID_HANDLE_VALUE Then
SafeToFile( _
hFile, _
@Comment, _
256, _
1 _
)
CloseHandle(hFile)
End If