i use file_lock from the boost interprocesses library to check if another instance of my program is running (since it is cross-platform and if the program crashes it will unlock it and nothing will be left behind), like this:
std::string lock_path = (globals::linux_user ? (globals::home + "lock") : "C:\\ProgramData\\lock");
std::ofstream file(lock_path);
file.close();
boost::interprocess::file_lock flock(lock_path.c_str());
if (!flock.try_lock())
exit(0);
flock.try_lock() tries to lock the file, and if another process has it locked, it will halt and exit the program.
this works beautiful on linux, but when it comes to windows it always return 1 (meaning that i locked it succesfully) when running other instances that have also locked it succesfully.
The directory path is not an issue, since i even changed it to use the current path plus the file is being created succesfully.
I tried putting some junk into the lock file, no changes.
I am using the same version boost for linux and windows.