471,573 Members | 1,039 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,573 software developers and data experts.

Problem with dynamic fopen with windows mobile

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.
Aug 28 '07 #1
0 3280

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Nick White [MSFT] | last post: by
1 post views Thread by Thomas | last post: by
11 posts views Thread by zaebos | last post: by
2 posts views Thread by yanlu06 | last post: by
11 posts views Thread by julie.siebel | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.