Hi I am having a problem and can not for the life of me figure out what is wrong.
I have a program that iterates through every file in a directory using FindFirstFile and FindNextFile and add them to a linked list. Then after adding all the files I want to read them in one at a time and send them over a socket connection.
I am succesfully iterating through all the files adding them to the linked list and retrieving them from the linked list but when I try and open them for reading using fgetc(filename) it ternminates prematurelly with error code 32 (ERROR_SHARING_VIOLATION 32 ::The process cannot access the file because it is being used by another process. )
I looked long and hard for where the file may have been used by another process and not properly closed. In order to do that I added some debug statements and found out that if I open the file with a hardcoded name ie "fileName" and not with a char* that contains that file name everything works great. for example here is what I have
if((file = fopen("\\MyFilePath\\data\\file001.mfr","r")) != NULL) {
count = 0;
while((byte = fgetc(file)) != EOF) {
count++;
}
printf("%d bytes read,error and eof values %d and %d\n\n",count,ferror(file),feof(file));
}
fclose(file);
strcpy(filePathPtr,"\\MyFilePath\\data\\file001.mf r");
if((file = fopen(filePathPtr, "r") != NULL)) {
count = 0;
while((byte = fgetc(file)) != EOF) {
count++;
}
printf("File read with %d bytes and error values %d and %d\n",count,ferror(file),feof(file));
fclose(file);
if((file = fopen("\\MyFilePath\\data\\file001.mfr","r")) != NULL) {
count = 0;
while((byte = fgetc(file)) != EOF) {
count++;
}
printf("\n\nAfter I could not read it can I still read? %d bytes and error values %d and %d\n\n",count,ferror(file),feof(file));
The printout looks like this:
115 bytes read,error and eof values 0 and 16
File read with 0 bytes and error values 32 and 0
After I could not read it can I still read? 115 bytes and error values 0 and 16
The only thing I can think of is for Windows Mobile 5.0 there is something wrong with passing in a standard char*. Is there another way around this, or has anyone experienced this before and found a solution or work around.
Thanks in advance I have been bashing my head against the wall on this one for awhile.