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
nc.ctComparisonType = REG_CT_ANYCHANGE;
nc.TargetValue.dw = 0; // ignored for REG_CT_ANYCHANGE


HRESULT hr = ::RegistryNotifyCallback(
&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(
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: , , ,

This information will help you to find out more about the best UK university. It's important to know
IEEE Project Domain management in software engineering is distinct from traditional project deveopment in that software projects have a unique lifecycle process that requires multiple rounds of testing, updating, and faculty feedback. A IEEE Domain project Final Year Projects for CSE system development life cycle is essentially a phased project model that defines the organizational constraints of a large-scale systems project. The methods used in a IEEE DOmain Project systems development life cycle strategy Project Centers in Chennai For CSE provide clearly defined phases of work to plan, design, test, deploy, and maintain information systems.

This is enough for me. I want to write software that anyone can use, and virtually everyone who has an internet connected device with a screen can use apps written in JavaScript. JavaScript Training in Chennai JavaScript was used for little more than mouse hover animations and little calculations to make static websites feel more interactive. Let’s assume 90% of all websites using JavaScript use it in a trivial way. That still leaves 150 million substantial JavaScript Training in Chennai JavaScript applications.
It is understandable that one is more confident when their task is in the hands of the Professional Essay Writing Help than a novice; thus, one hires Essay Writing Asssignment Help Writer who delivers the ideal Custom Essay Paper.

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.
Thank you very much for giving space to us to express our feeling and thoughts about above information. I think you will keep updating and changing these information time to time if there is need to change. new company registration in delhi , top chartered accountant firms in india, gst registration in delhi online , business advisory consulting services in india, accounting companies , Inventory management in Delhi.
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
This is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog..
affordable seo agency
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 certification

Product owner certification

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 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


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


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.

Post a Comment

<< Home

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