This is the function in question...
What happens is the user opens notepad, if notepad is open then they are required to type a password.. If its invalid, notepad is closed.. if the password is valid, it continues.. else if the user hasn't entered a password within 10 seconds, timeout..
So the function works when the password is valid/invalid.. the problem is when the user times out, and they open notepad again, they cannot enter the password as it wont allow them..
Try compiling the attached .cpp file and see what I mean..
void pwget()
{
string password;
password.clear();
REPEAT
char cProcess[80] = "notepad.exe";
DWORD dwReturn;
dwReturn = CountProcesses(cProcess);
if(dwReturn != -1)
{
if(dwReturn == 1)
{
cout<<"User Attempted to Open Program!\n\n";
using namespace jsw::threading;
char pword[1024];
auto_event e;
LPVOID args[2] = {pword, &e};
thread worker = thread::start(get_password, args);
if (e.wait(10000)){
string password(pword);
if(password == "brandon")
{
system("cls");
cout<<"Password was entered correctly.\n\n";
Sleep(1000);
system("cls");
break;
}
else
{
system("cls");
cout<<"Password is Invalid...\n\n";
Sleep(1000);
system("taskkill /IM notepad.exe");
cout<<"\n";
system("cls");
cout<<"Welcome to GameBlock v1.0\n\n";
pwget();
}
}
else {
worker.abort(NO_ERROR);
cout<<"\n\nUser Timedout..\n\n";
Sleep(1000);
system("taskkill /IM notepad.exe");
cout<<"\n";
system("cls");
cout<<"Welcome to GameBlock v1.0\n\n";
pwget();
}
}
else if(dwReturn == 0)
{
cout<<"Program Not Running\n";
Sleep(1000);
main();
}
}
UNTIL((password == "brandon"));
password.clear();
cout<<"In Minutes, enter the length of time the program should run: ";
cin>>x;
cin.ignore();
x = x*60;
}
Extra problems but not required to help fix: Timer Pause function doesnt work.. Find by me for now. I would just like help on why they cannot enter the password when it timesout.