Jump to content
  • Advertisement
Sign in to follow this  
JamesCobras

Wake from sleep, Vista Version

This topic is 3256 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, i have a small problem, which i'm sure one of you code gurus can help me fix. I have the following code that works with XP
    hTimer = CreateWaitableTimer(NULL, NULL, NULL);

	if (GetLastError() == 0)
	{
		std::cout << "Timer Status: Success\n";
	}
	else
	{
		std::cout << "Timer Status: " << GetLastError()<< "\n";
	}
    
	

    SetWaitableTimer(hTimer, &SleepTime, 0, NULL, NULL, TRUE);
    
	if (GetLastError() == 0)
	{
		std::cout << "Timer Setting Status: Success\n";
	}
	else
	{
		std::cout << "Timer Setting Status: " << GetLastError()<< "\n";
	}

	

	std::cout << "Ready to Suspend. Do you want to continue? (y/n)\n";

	std::cin >> sleepcheck;

	if (sleepcheck == 'y')
	{
		FirstThread = CreateThread
					(
					NULL,
					NULL,
					RunFile,
					NULL,
					CREATE_SUSPENDED,
					NULL
					);

		std::cout << "Suspending.....\n";
		if(!SetSuspendState(FALSE, FALSE, FALSE))
		{
			std::cout << "Could Not Suspend, Please Contact us at Myndoko.com, we will try to assist you ASAP!\n";
		}
		

		std::cout << "Back....\n";
		std::cout << "Running File(s)\n";
		ResumeThread(FirstThread);



		std::cout << "Waiting for All Processes to be Terminated\n";
		WaitForSingleObject(FirstThread,INFINITE);
	}

It works great all the time, but when i try to use the same code on a vista machine (i have tried 2). The wake up from the SetWaitabletimer() function fails!! i.e. the machine doesn't wake up!! This lead me to look at the new api and i made some quick adjustments e.g. using SetWaitabletimerEx().
   hTimer = CreateWaitableTimerEx(NULL, NULL, NULL,TIMER_ALL_ACCESS);

	if (GetLastError() == 0)
	{
		std::cout << "Timer Status: Success\n";
	}
	else
	{
		std::cout << "Timer Status: " << GetLastError()<< "\n";
	}
    
	




    SetWaitableTimerEx (hTimer, &SleepTime, 0, NULL, NULL, NULL, 1000000);
    
	if (GetLastError() == 0)
	{
		std::cout << "Timer Setting Status: Success\n";
	}
	else
	{
		std::cout << "Timer Setting Status: " << GetLastError()<< "\n";
	}

	

	std::cout << "Ready to Suspend. Do you want to continue? (y/n)\n";

	std::cin >> sleepcheck;

	if (sleepcheck == 'y')
	{
		FirstThread = CreateThread
					(
					NULL,
					NULL,
					RunFile,
					NULL,
					CREATE_SUSPENDED,
					NULL
					);

		std::cout << "Suspending.....\n";
		if(!SetSuspendState(FALSE, FALSE, FALSE))
		{
			std::cout << "Could Not Suspend, Please Contact us at Myndoko.com, we will try to assist you ASAP!\n";
		}
		

		std::cout << "Back....\n";
		std::cout << "Running File(s)\n";
		ResumeThread(FirstThread);



		std::cout << "Waiting for All Processes to be Terminated\n";
		WaitForSingleObject(FirstThread,INFINITE);
	}

And it still won't work. Anyone familiar with Windows 7 / Vista api or the functions in general. Help code genies, any help from anyone would be appreciated. JamesCobras

Share this post


Link to post
Share on other sites
Advertisement
It could be a BIOS issue. I believe you need to enable wake-on-timer in the BIOS for it to actually wake the computer back up again.

Also, watch out for SetWaitableTimerEx (etc), since it's Windows 7-only (i.e. it's not in Vista anyway).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!