Thierry,
I am not sure what would be the cause of this, though that error seems to indicate an invalid handle value. However, you did report that in your debugging, you were seeing a positive value for the handle.
I have seen error occur in some large application cases where handles weren't been closed out or discarded properly, or if too many handles were opened at once (though this typically numbered in the thousands). Are you multithreading your application at all, or are there any other function calls between the OpenFile and WriteFile that might be causing this? Also, if this log file is being written to, and is being viewed by another application, this could cause an error.
Daniel McChane
Application Engineer
National Instruments