free web page counters

Windows Mobile Pocket PC Smartphone Programming

==>Click here for the SiteMap<==. Original contents with decent amount of source codes.

Thursday, May 11, 2006

Pocket PC Power Management Series 11: Play sound (for example, wav file) when a Pocket PC is suspended

====>SiteMap of this Blog<===

Pocket PC Power Management Series 11: Play sound (for example, wav file) when a Pocket PC is suspended

I am going to write a new series on Pocket PC Power Management topic: How to play sound when Pocket PC is sleeping or suspended. Let me use a simple API to achieve this purpose: PlaySound.

Why care?

If you read my previous series on the Power Management topic, you may ask why we care. If the Pocket PC sleeps, no thread can run, so PlaySound won't even be called. If the PPC is not sleeping, PlaySound is called, so why the hassle? The answer is: Yes, PlaySound will be called, but you may not hear the sound! So the title of this blog is sort of misleading. It should be changed to something like "How to make sure there is a sound when the device is suspended".

Let us say, you write the code to request the PPC to play a wav file, even when it is suspended. A good example is the Alarm program. It might need to play a warning or ringtone at 8PM. This piece of code can be executed at 8PM, guaranteed by Windows CE OS. However, you may be disappointed not hearing any sound. Below I will explain why and how to solve the problem.

Why no Sound?

Ultimately a peripheral device needs to emit the sound. This peripheral must be powered or put into certain state so as to vibrate to produce sound waves. A good chance is: When PlaySound() is called, the Pocket PC is in such a "System Power State" that the sound peripheral is not supposed to work; or in Microsoft terms, the sound peripheral is in such a "Device Power State" mapped from the current "System Power State", that the sound peripheral might have no power, have low power or in standby mode.

For our specific alarm example, the Pocket PC might be in a "System Power State" called "Unattended". The sound peripheral is called "wav1:", which is put into a "D4 Device Power State", mapped from "Unattended" state. "D4" means "No Power", so you won't be able to hear any sound.

To above explanation might be too abstract. If you really need to understand those terms, please read Microsoft Platform Builder documentation on "Power Management".

A Possible Solution

A possible solution to the problem is to change the mapping, so as to change the power state of "wav1:" device. The following code snippet is doing this job:

HRESULT ChangeWav1Mapping()
{
   LRESULT lr = E_FAIL;

   HKEY hKey = NULL;
   DWORD dwSubKeys = 0;
   DWORD dwMaxSubkeyLen = 0;
   TCHAR szSubkeyName[MAX_PATH];

   lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("\\System\\CurrentControlSet\\Control\\Power\\State"), 0, 0, &hKey);
   if (ERROR_SUCCESS != lr) goto FuncExit;

   lr = RegQueryInfoKey(hKey, NULL, 0, 0, &dwSubKeys, &dwMaxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL);
   if (ERROR_SUCCESS != lr) goto FuncExit;

   for (int i=0; i<dwSubKeys; i++) {
      DWORD dwSubkeyNameLen = MAX_PATH-1;
      memset(szSubkeyName, 0, MAX_PATH*sizeof(TCHAR));
      lr = RegEnumKeyEx(hKey, i, szSubkeyName, &dwSubkeyNameLen, NULL, NULL, NULL, NULL);
      if (ERROR_SUCCESS != lr) continue;
      
      //ALERT(szSubkeyName);

      HKEY hSubkey = NULL;
      lr = RegOpenKeyEx(hKey, szSubkeyName, 0, 0, &hSubkey);
      if (ERROR_SUCCESS != lr) continue;

      // any wav1: ?
      DWORD dwValueType = 0;
      DWORD dwValueData = 0;
      DWORD dwValueDataLen = sizeof(DWORD);
      lr = RegQueryValueEx(hSubkey, TEXT("wav1:"), NULL, &dwValueType, (LPBYTE)&dwValueData, &dwValueDataLen);
      if (ERROR_SUCCESS == lr && 0 != dwValueData) {
         dwValueData = 0;
         RegSetValueEx(hSubkey, TEXT("wav1:"), NULL, REG_DWORD, (LPBYTE)&dwValueData, sizeof(DWORD));
      }
      RegCloseKey(hSubkey);
   }

   RegFlushKey(hKey);

FuncExit:
   if (hKey) {
      RegCloseKey(hKey);
   }

   return S_OK;
}

Notice this is a piece of bad code. It forces the "wav1:" device to be always powered, no matter what state the Pocket PC is in. Looks like that is the case for most Pocket PC 2003 devices, but probably not true for Pocket PC 5.0 device. So the above code effectively changes the sound behavior of PPC 5.0 device.

The recommended API to use to SetPowerRequirement and ReleasePowerRequirement. I will talk about them in a later post.

Wrap Up

Pocket PC sleeps. Read the following two posts for basis:

There are ways to force the device not to sleep, or request it to run a program at certain time or upon certain event:

The above techniques force the CPU to run, but not necessarily other peripheral devices. In this post we talked about "wav1:" and a possible hacky way to override the power mapping.

====>SiteMap of this Blog<===




[ [permalink] ]

16 Comments:

At November 19, 2006 8:00 PM, Blogger blanjo-antivirus said...

Nice Blog, Best Information and Best Article!!!
we Wait new posting from this blog.

Find another Best & complete links :

TIPS TO BUY LAPTOP
Before you buy Laptop/Notebook or If you want to buy Laptop/Notebook, we give you Tips To Buy Laptop/Notebook. This tips can help you , how to choise your dreams Laptop/Notebook ... more ...
Tips To Buy Laptop

LAPTOP & NOTEBOOK CENTER
All Information About Laptop/Notebook
Find Best Seller laptop and Top 10 Laptop ( Laptop toshiba, laptop acer, laptop ibm, laptop nec and much more ... ), include best Laptop photos, laptop Bag, Laptop Accessories, Laptop DVD & much more ...
Best Laptop

ANTIVIRUS GROUP
Our Antivirus Group can Help you if your computer have problem with many Virus , Worm, trojan, trojan horse.So, find now antivirus for ...
Download Free Antivirus Software

MAKE MONEY ON INTERNET
If you Interrest Make Money on internet you can learn here and we give tutorial how to make money on internet. find our tutorial for make money on internet ...
Online Business

WEBSITE PROMOTER
With Website Promoter you can know how to promote your site, how to make rangk on internet search engine ...
Website Promoter

ANTIVIRUS CENTER
Our Antivirus Center : here you can free Download Software Antivirus for remove all virus , trojan, worm virus W/32. You can choise, what is a good software antivirus for your computer specification.
Best Antivirus For Pc/ PDA/ Smartphone/ Laptop n Notebook

FREE HTML TEMPLATE
you can find here, If you want to learn more about internet, website, homepage.Ex: Here you can learn how to build website with html template ,complete with tutorial how to make quickly website, so ...
Free Template For Website Builder

DATING ONLINE SERVICE
If you want looking girl, partner for live, dreams woman, man , boy you can find, looking and dating online here, this dating online service is best for find your dreams ...
Fun Dating Online

NEW ANTIVIRUS BRONTOK
If you have still problem with virus rontokbro / brontok, rontokbro.eq, decoil, w32/khillav/w32/killav you can find here new antivirus for remove all virus brontok, new virus brontokvirus brontok here. our antivirus new and updated
New Antivirus Brontok/AntiRontokbro

ANTIVIRUS DECOIL
If you have still problem with virus decoil, dkernel, dekernel you can find here new antivirus for remove all virus decoil on your computer.so, find software for remove virus decoil ...
Antivirus Decoil, Decoil Removal


By : Blanjo Antivirus Company
Best Partnert This Blog

 
At February 21, 2007 11:45 PM, Anonymous Anonymous said...

Hi.
I saw your post about MAPI.i have a question.
When i try to find message store related to sms,i check the string of pr-display to be SMS,i find out that in some devices it is 'default'.
beside checking the string is there any way to find the msg store of SMS

thanks

 
At June 18, 2007 3:05 AM, Anonymous John D Wilson said...

I'm looking for the best solution to my predicament;
I have a GPS Tracking app written in C# and when the device suspends the the GPS signal is not processed, I can prevent the device from suspending, but that leaves the backlight on, I can turn the screen off and leave the device in awake mode but I because my app runs in the background I want to be able to turn the screen off after a period of inactivity.
Please help ASAP

 
At October 21, 2007 7:37 AM, Blogger pocketpc said...

Very good!
My site http://www.pocketfree.blogspot.com/ hosts the latest and most interesting PocketPC Freeware and News. You're welcome to post links of such programs to be published on the site on pocketfree@gmail.com

 
At February 11, 2009 12:14 AM, Blogger uiyui said...

Today is the gold für wow second day of 2009 ,world of warcraft gold it also a mesos special for me .cheap wow gold Because i have cheap maplestory mesos a chance to go to an english speech of LiYang and crazy to learn english follow him . He is a firendly,kindly person who make me feel good.wow gold kaufen What‘s more ,maple story mesos he very confidence .And he make me sure what he can do i also can do,as long as i make a determination and force myself to do it every second,Crazy just like him .wow geld I learn one setence from his book ever :maple story items If you want to succeed always force yourself to do more .I can't agree more with him .wow gold farmen To be honest ,when i was a littel girl i already fall in love with english.But what a pity i am poor in english ,Maple Story Account and it make me feel frustrating .So i want to give up many times ,but i can't as i still love it .So i tell mysefl :if you think you can you can wow leveling,and all your maple story power leveling hard work will pay off.wow power leveling Today i am very happy i can listien this wonderful speech of LiYang. I reap a great benifits from him .maple story money As he say :i am the best ,and every one can do it . world of warcraft power leveling Yes,i belive i can do it if i crazy as he buy archlord gold.Now i want to say :i will never give up.

 
At March 23, 2009 12:12 AM, Blogger Mirela said...

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.


Sarah

http://laptopseries.net

 
At April 21, 2009 5:28 PM, Blogger game gold said...

At one time or another, I do not have the rf gold ; at the first time, I am not willing to buy rf online gold . But I do not wonder I buy the rf money , my friend thinks that I am ill. But when I have it, it carries the magic from such a group, such a link in the world, rf cp , it is the key bring you to this world. But buy cheap rf gold is the best desire that I make.

Without thinking I buy some runescape gold . I use some buy runescape and want to find a good group. We often buy rs gold together on Monday. As if it is a rule. I think it is the real friendship. runescape money is already become the essential thing in my life. So I will introduce my friends have the cheap rs gold , we can be consist of a group, it must be very interesting.

 
At April 24, 2009 5:43 PM, Anonymous Anonymous said...

I want give they happy time, twelve sky Gold, I work here with 12sky gold. Though, I can not make much money, twelvesky Gold, But I want to Exercise myself, 12Sky Silver Coins, I get up early 12 sky goldI always believe the angel is being and 12sky2 Gold . In fact, we all like listening to the songs of milk tea twelve sky2 Gold .
Generally speaking, I think is her voice very comfortable and mood of the story twelvesky2 Gold , We feel life bit by bit, looking forward the love belonging of the life feelings buy 12sky2 Gold , you will love milk tea like me, let us love her together and play cheap twelve sky2 Gold .

 
At April 24, 2009 9:16 PM, Anonymous Anonymous said...

Do you know cabal online alz? I like it.
My brother often go to the internet bar to buy cabal alz and play it.
After school, He likes playing games using these cabal gold with his friend.
I do not like to play it. Because I think that it not only costs much money but also spend much time. One day, he give me many cabal money and play the game with me.
I came to the bar following him and found buy cabal alz was so cheap. After that, I also go to play game with him.

Do you know dofus kamas? I like it.
My brother often go to the internet bar to buy kamas and play it.
After school, He likes playing games using these cheap kamas with his friend.
I do not like to play it. Because I think that it not only costs much money but also spend much time. One day, he give me many dofus gold and play the game with me.
I came to the bar following him and found buy dofus kamas was so cheap. After that, I also go to play game with him.

 
At April 24, 2009 9:43 PM, Anonymous Anonymous said...

I always heard something from my neighbor that he sometimes goes to the internet bar to play the game which will use him some Perfect World Gold, he usually can win a lot of Buy Perfect World Gold, then he let his friends all have some Perfect World Silver, his friends thank him very much for introducing them the Perfect World money, they usually cheap Perfect World Gold together. It is the pw gold always make them happy.
I am so happy to get some Pirates of the Burning Sea Gold and the potbs gold is given by my close friend who tells me that the potbs Doubloon is the basis to enter into the game. Therefore, I should potbs money with the spare money and I gain some buy potbs Doubloon from other players.

 
At April 24, 2009 10:11 PM, Anonymous Anonymous said...

Do you know that the knight gold, and do you want to know? In the game many players need the knight noah to up their levels. so they often search where can buy the knight online gold, I think our website is your choice. Many friends told me that in here can knight online noah, and you will also practice your online games skills. So i hope more and more players come here to buy the cheap knight gold.
What do you know requiem gold. And do you want to know? You can get requiem lant here. And welcome to our website, here you can play games, and you will get requiem money to play game. I know cheap requiem lant, and it is very interesting.Do you want a try, come and view our website, and you will learn much about requiem online gold.

 
At April 25, 2009 2:10 AM, Anonymous Anonymous said...

Have you heared about 9Dragons which you need use Anarchy credits to play, and you can also borrow Anarchy Online credits from other players? But you can buy AO credits, or you will lose the choice if you do not have Anarchy online gold. If you get Anarchy gold, you can continue this game.
Have you heared about 9Dragons which you need use 9Dragons gold to play, and you can also borrow 9 Dragons gold from other players? But you can buy 9 Dragons gold, or you will lose the choice if you do not have cheap 9Dragons gold. If you get 9Dragons money, you can continue this game.

 
At April 25, 2009 2:57 AM, Blogger feilin said...

I like hero gold very much because it is very useful. In fact at first sight I have fallen in love with hero online gold. So no matter how much I have spent to buy hero gold, I never regret. Because of hero online money, I meet a lot of friends. So I never hesitate to buy hero money.
My friends and I like to buy habbo credits, because the habbo gold is very useful to upgrade equipment. Only your equipment becomes better, then you can win this game. In habbo coins, you can buy everything you want in this game. Tomorrow will be my birthday, so my friends promise to buy habbo gold as gifts. I am so happy. They understand me so well, cheap habbo credits is my favorite.

 
At April 27, 2009 4:09 AM, Blogger Rajesh said...

Please tell me how standby the WinCE O/S in the absence of external charger and resume when charging is ON?

 
At August 09, 2009 4:06 PM, Anonymous Anonymous said...

Online poker texas holdem free bonus. No veryfication no id needed no risk at all.
Play with other players free bankrolls no id required all possible $50 bankrolls.
starting bankrolls and capital $50 bonus poker. Stay away, get more cheap poker promotion.
once you have free starting poker capital from bankrollmob.
Over fifty sponsors dollars poker bonus darmowe pieniądze bez depozytu tylko czyszczenia za darmo.
Ale także bez wpłaty no i mansion bet most,poker darmowe free czyszczenia no risk, no deposit.
on line promo wow bonus sign up poker account for free huge and gift promotion.
free no deposit need id sign tapicerki. Dlatego zarabiaj online karcher no deposit information for poker,
more and free no deposit sponsorship no id verify from bet poker blog.
money czyszczenie poker sławków dąbrowa katowice chorzów. wyrzynarke meblową z karcher odkurzaczem, tanio i śmiesznie cheap. poker capital no id katowice ślask ale także online odbywa się szybko i dokładnie wow.
Promocje związane z czyszczenie wykładzin tapicerek jest na prawdę tanie online free.
Czyszczenie odbywa się u klienta.

 
At October 02, 2009 11:46 AM, Blogger pedro velasquez said...

In my two previous Pocket PC Power Management Series (Series 5 and Series 6), sportsbook I am trying to tackle the task of writing either continuously-running or periodically-running programs. I must admit such programs do not fit nicely into Microsoft's Windows Mobile-powered Pocket PCs, after having working on such applications myself for more than 1 year. Why? The fundamentally-flawed design of the Pocket PC devices prevent any good developer from developing really battery friendly programs.
When bet nfl Pocket PC device was initially designed, Microsoft made the decision that the device should never shutdown, probably by following Palm's design. Unless battery is removed, the device is always "alive". Unfortunately, Microsoft's OS is a trimmed version of its bigger brother Desktop Windows. Desktop Windows was never designed to be CPU or power http://www.enterbet.com friendly; in fact, desktop Windows seems to be proudly following the path of being more and more power hungry

 

Post a Comment

Links to this post:

Create a Link

<< Home