the thread that Roger Binns pointed out (with similar problems in an app called "subversion") seems to be right on the money. The problem is associated with unrelated processes doing background file operations. I wrote a test program, and found it fails for me if I run it in a directory which is shared using windows' file sharing for macintosh. This is a feature present only on winxx-server, but I suspect it will also fail in other, more common, configurations. Needless to say, it's extremely serious if CreateFile can fail for no locally apparent reason!
Here is the test program: -- #include <windows.h> #include <stdio.h> #define filename "test.file" #define fileflags FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_DELETE_ON_CLOSE int main(int argc,char **argv,char **envp) { long i; for(i=0;;i++) { char buf[100]; char rbuf[100]; char errbuf[256]; HANDLE ff = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, fileflags, NULL); if(ff==INVALID_HANDLE_VALUE) { sprintf(errbuf,"gen %d file create error %d\n",i,GetLastError()); perror(errbuf); exit(1); }; sprintf(buf,"file generation %d\n",i); { long len=strlen(buf); long wlen = 0; if((0==WriteFile(ff,buf,len,&wlen,NULL)) || (wlen!=len)) { sprintf(errbuf,"gen %d file write error %d\n",i,GetLastError()); perror(errbuf); exit(1); }; if(0!=SetFilePointer(ff,0,NULL,SEEK_SET)) { sprintf(errbuf,"gen %d file seek error %d\n",i,GetLastError()); perror(errbuf); exit(1); }; if((0==ReadFile(ff,rbuf,len,&wlen,NULL))|| (wlen!=len)) { sprintf(errbuf,"gen %d file read error %d\n",i,GetLastError()); perror(errbuf); exit(1); }; if(memcmp(rbuf,buf,len)!=0) { sprintf(errbuf,"gen %d file compare error %d\n",i,GetLastError()); perror(errbuf); exit(1); }; if(0==CloseHandle(ff)) { sprintf(errbuf,"gen %d file close error %d\n",i,GetLastError()); perror(errbuf); exit(1); }; } } }