Thank you Rolf, I refactored the code to use the CVI file functions and CreateFile()/CloseHandle() and this seems to have solved my problem.
The speed issue is also gone. I made sure to include windows.h and use the Windows API functions.
Thanks again. My savior:)