Discussing the nuts and bolts of software development

Thursday, May 10, 2007

 

Why, that's just SNAPI!

Windows Mobile 5 is the new version of Windows CE 5.0 that is targeted at the Windows mobile market. It is the underpinnings of both the Pocket PC and Smartphone editions.

Windows Mobile 5 comes packed with some new (native) features and APIs such as:
Perhaps I'm simply too much of a geek, but SNAPI is just a cool name. Go ahead, say it out loud. "SNAPI". Now say it with a Sean Connery voice. "SNAPI". Damn cool.

SNAPI is a great improvement to Windows Mobile, long overdue. Basically SNAPI is a registry notification system. You receive events when keys or values you are watching are changed in the registry. You can use SNAPI on any sub-key or value in the registry. However there are some pre-defined helpers specifically related to the state of the device. For a full list see snapi.h.

In my last Windows Mobile project, I used SNAPI for many things, some of which I will get into in later posts, but perhaps the easiest use was to register for the battery state notifications.

Some devices show the battery strength indicator in the shell notification area of the screen and some show it only on the "Today" screen; we had a requirement to show the battery strength on the application's main screen.

This is a common requirement, in past non-WM5 projects, we had to set up a thread and to poll the value, update the screen, then repeat. Not hard, just tedious.

In WM5 however, all we needed to do was to register to that notification. Registering is easy:
// Battery strength
NOTIFICATIONCONDITION nc = { 0 };
nc.ctComparisonType = REG_CT_ANYCHANGE;
nc.dwMask = SN_POWERBATTERYSTRENGTH_BITMASK;
nc.TargetValue.dw = 0; // ignored for REG_CT_ANYCHANGE

HREGNOTIFY regNotify;

HRESULT hr = ::RegistryNotifyCallback(
SN_POWERBATTERYSTRENGTH_ROOT,
SN_POWERBATTERYSTRENGTH_PATH,
SN_POWERBATTERYSTRENGTH_VALUE,
onBatteryStrengthChangedCallback,
0,
&nc,
&regNotify );

// save hr if successful somewhere for later use

RegistryNotifyCallback registers a transient notification request that will be used to notify the caller via the specified callback when the value of the sub-key changes. Transient simply means that the registration to the registry notification will not survive a device reset.

It's important to note that when notified of changes via the callback, the callback is executed on a private thread separate from the one called RegistryNotifyCallback.

If the value or the key does not exist at time of registration, the caller will be notified when the value or key is added.

The callback has to have the following signature:
void onBatteryStrengthChangedCallback(
HREGNOTIFY hNotify,
DWORD dwUserData,
const PBYTE pData,
const UINT cbData )

Now that we're registered, the supplied callback will be called whenever the battery strength changes. A sample implementation of the call back could be as follows:
// pData contains the new value for SN_POWERBATTERYSTRENGTH_VALUE.
DWORD batteryStrength;
batteryStrength = (*(DWORD*) pData);
batteryStrength = ( batteryStrength & SN_POWERBATTERYSTRENGTH_BITMASK ) >> 16;

// update the screen
...

See, very simple. When don't want to get the notifications anymore, just call:
// hr was what was returned from registering successfully to the notification.
::RegistryCloseNotification( regNotify );

This API has to be called to stop receiving the notification and to close the handle.

There are however, some caveats with using this API: how often the value changes in the registry is dependent on the device. Some devices only update the value when the actual strength hits a predefined boundary, such as 75%, 50%, or 25%. The value also gets changed when you plug in the device to be charged, and then unplugged. On some devices I see the strength go briefly from 100% to 0% when un-cradled.

As you can see SNAPI provides alot of functionality, and is a pretty flexible API. In future posts I hope to explore this API in further detail.

Labels: , , ,


Comments:
This information will help you to find out more about the best UK university. It's important to know
 
The CSS coding is really helpful to me and I always read this type of post and now as a student of developer also looking for a professional essay writer in Karachi because I have faced a lot of burdens and also want to reduce the burden.
 
Wow!! This really is an informative post!!
Thanks for the share!!
For more
 
here are several easy steps, which include emergency cash loans for unemployed application process via the special online form, 10-15 min period of waiting for the confirmation and getting the loan directly into your account. As you can see there is nothing easier and faster than getting fast cash with the help of loans for emergency situations, which personal loans for people on disability benefits always happen at the most unsuitable moment.
 
SNAPI is a big improvement to Windows Mobile, of late. Basically, SNAPI is a registry notification system. You get events when the keys or value you are viewing change in the registry. You can use SNAPI on any small key or value in the registry. However, the aforementioned auxiliaries are essentially related to the condition of the device. You can go to website now. For a full list see snapi.h. In my last Windows Mobile project, I used SNAPI for many things, some of which I will log into the posts later, but perhaps the easiest use is to sign up for battery state notifications.
 
Really amazing
keezon
 

Excellent content ,Thanks for sharing this .,
Leanpitch provides online training in CSPO everyone can use it wisely.,
Join Leanpitch 2 Days CSPO Certification Workshop in different cities.
CSPO TRAINING

CSPO certification online
 

Excellent content ,Thanks for sharing this .,
Leanpitch provides online training in CSPO everyone can use it wisely.,

Certified scrum product owner

CSPO online certification

 

Excellent content ,Thanks for sharing this .,
Leanpitch provides online training in CSPO everyone can use it wisely.,

CSPO certification cost

CSPO TRAINING ONLINE
 
All of the experts on our team www.freepaperwriter.com are pre-screened and have at least 1+ years of experience in helping students achieve academic success. See how we select our employees.
 
Thanks for the providing service for Residential garage doors Plano TX. It’s a great post, you really a good writer! I’m so glad someone like you have to provide us, your efforts and dedication provide the customers, for this type of service makes easy, Helpful and Useful to them.
 
Hey! Each of us was at least once faced with uncertainty about the grammatical correctness of our text and the correctness of the tone you used! To avoid this problem, I advise you go to this page and use our online tool for finding and correcting errors in your text. Come on in and try how simple it is.
 
This article is such a nice and interesting one, I'm very satisfied with the provided contents. I hope more excellent articles would be posted in your website. Thank you so much for this and keep sharing.The top Dubai App Development company provides best service you visit here site fore more details.Get best Dubai App Development service you visit here site to get more info.
 
I must say that I'm in the right place. free ZAMSU post utme past questions pdf
 
it is very helpful.nice article. thanks for sharing these information with all of us. Kinemaster Gold

 
Home Cleaning Services Gurgaon @ Door Step. We have a group of qualified home cleaners that are fully trained and equipped with skills to deliver professionalism for your home cleaning and office cleaning needs. Maybe you would like to enjoy the pleasures of a clean home, take pride in your meet new friends, and get back a clear mind. You need different kinds of benefits of this service as soon as possible. Give us a call! We are in Delhi(India).

 
Harry James is currently working as a business consultant.you have access to all the information and qualified MCA leads. Several sources taken together.We offer MCA Leads data regardless of its age, freshness, source, or bundles.


 
his article is such a nice and interesting one, I'm very satisfied with the provided contents. I hope more excellent articles would be posted in your website.
film plus apk
 
This comment has been removed by the author.
 
Most lenders in Illinois don’t run hard inquiries on borrowers’ credit history $300 Payday Loan through those three main credit bureaus. These checks are called “soft credit checks” because of their simplicity.
 
This post is really helpful. Thanks for sharing the coding. Keep posting more tech blogs which is useful for us. Uncontested Divorce Lawyer Fairfax VA
 
This post is really informative for me and much Thanks for sharing the coding. Keep posting more tech blogs which is useful for us. custom software development services
 
In iOS app development, both UX (User Experience) and UI (User Interface) play crucial roles, but their importance varies. While UI focuses on the visual aspects and aesthetics of an app, UX emphasizes the overall user journey and satisfaction. In iOS app development, prioritizing UX is much more important as it ensures intuitive navigation, seamless interactions, and ultimately enhances user engagement and retention. However, a well-designed UI complements UX, enhancing the overall user experience. Thus, prioritizing UX is paramount in iOS app development for long-term success.
 
Long delayed, SNAPI is a fantastic addition to Windows Mobile. SNAPI is essentially a notification mechanism for the registry. When values or keys you are monitoring are modified in the registry, you are notified through events. Any sub-key or value in the registry can be used with SNAPI. I appreciate you offering such excellent content. I learned something from your blog. Keep the word going.


 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?