LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

file handle problem

In a large application structured in many levels, we have log file at each level.
Some times we have and message "invalide file handle" when we try to write a file with the WriteFile instruction but every time we test the return of the OpenFile instruction and there is a positive number inside.
Each handle is closed after use.
We expreiment more problem when the file is on a server.
Doese any persone have an idea of what can I do to solve the problem ?

Thank you very much
Thierry Vorms
0 Kudos
Message 1 of 4
(3,280 Views)
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
0 Kudos
Message 2 of 4
(3,280 Views)
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
0 Kudos
Message 3 of 4
(3,280 Views)
thank you for your response.
Each log file is managed by only one methode
Typically method is:

if ((log_file_handle = OpenFile (FileName, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII)) == -1)
return UNABLE_TO_WRITE_IN_LOG_FILE;

WriteFile (log_file_handle, buffer, strlen(buffer));
CloseFile (log_file_handle);

The error appear in the WriteFile function.
The application is in debug compilation mode and i can see the log handle is positive.

The problem doesn't appear in the same log file all the time.

I have only one thread more than the master thread and all log file is written in the same thread.

Thank you in advance for your help
0 Kudos
Message 4 of 4
(3,280 Views)