Don't use GetCurrentDirectory
Use GetModuleFileName or other...
Read file at startup

ArielVW
1
Reputation point
I made an application to read files and the application runs normally. But the problem is when the computer is restarted this application can't read the file (I've entered the application path to registry HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run manually).
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <windows.h>
int main(void ) {
TCHAR config[MAX_PATH];
GetCurrentDirectory(MAX_PATH,config);
strcat(config,"\\test.txt");
FILE* fPtr = fopen(config, "r");
if (fPtr == NULL){
fclose(fPtr);
printf("File not exists");
} else {
fclose(fPtr);
printf("File exists");
}
getchar();
return 0;
}
Windows development | Windows API - Win32
2,792 questions
2 answers
Sort by: Most helpful
-
Castorix31 90,686 Reputation points
2022-10-22T16:38:49.137+00:00 -
RLWA32 49,636 Reputation points
2022-10-22T16:42:48.197+00:00 Use the fully qualified path to the file in your code. The current directory when the user logs on is probably not the same as when you run your tests.