I am simply trying to import a text file into a text box in CVI 6.0 under XP.
What I did is GetFileSize , Allocate a buffer, OpenFile , Read file , SetCtrlVal of the text field to the buffer and close the file. The Problem is I am reading in junk at the end of the file and the bigger the file the larger is the junk , this junk is a repetition of part of the data of the file itself.
ResetTextBox (HelperWindow[1] , GCODEPANEL_GCODE_EDIT ," " );
GetFileSize (Filename, &Buffersize);
Buffersize++; // add one for /0 terminator
ChBuffer =calloc (Buffersize,sizeof(char));
FileHandle = OpenFile (Filename, VAL_READ_WRITE, VAL_OPEN_AS_IS, VAL_ASCII);
result = ReadFile (FileHandle, ChBuffer, Buffers
ize);
SetCtrlVal (HelperWindow[1] , GCODEPANEL_GCODE_EDIT ,ChBuffer);
result = CloseFile (FileHandle);
I tried making my own GetFilesize that counts characters till feof and it was correct but slow a 2Mb file take 10 seconds to measure . I hence beleive some data buffer is attached by windows after the eof marker but I wouldn't know a fast way to measure the useful part of a text file.This effect happens on all computers I tried , and it can be seen on small files.
Thanks David