Make sure that writepic is defined as a long and tempfile is an integer. After FileWriteEx you need to close the file.
tempfile = FileOpen(....)
writepic = FileWriteEx(tempfile, lblb_out)
FileClose(tempfile)
The return value from FileWriteEx should be the number of bytes written.