I encounter a problem about DeleteFile() with ANSI stdio functions.
It always fails to delete file and sets ERROR_SHARING_VIOLATION.
I know I can use remove() instead of DeleteFile(), but it make me confused.
Is MS File Management Functions and ANSI stdio functions not compatible?
the code is:
Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- #include <windows.h>
- int main(int argc, char* argv[])
- {
- FILE* fp = fopen("C:/testFS.txt", "wt");
- fclose(fp);
- // remove("C:/testFS.txt");
- if (DeleteFile(_T("C:/testFS,txt")) == 0)
- {
- // It always be here. why?
- DWORD err = GetLastError();
- if (err == ERROR_SHARING_VIOLATION)
- {
- printf("ERROR_SHARING_VIOLATION\n");
- }
- else
- {
- printf("Other error: %d\n", err);
- }
- }
- return 0;
- }