
Chapter 20: Registry-based WWAN API
Sample Source Code
237
Psion Mobile Devices Developers Guide
documentation on MSDN. These APIs are not supported by Windows CE 6.0 R3. The following code looks
for changes of Status:
The following more complicated sample shows how to process all changes to values below a selected
registry key. This sample is based on a blog post
1
. The Microsoft documentation of
CeFindFirstRegChange() is incomplete, while the documentation of CeRegGetNotificationInfo()
is inaccurate.
1
geekswithblogs.net/BruceEitman/archive/2009/08/25/windows-ce-cereggetnotificationinfo-works-sort-of-part-3.aspx
DWORD ThreadProc(LPVOID lpParam)
{
HKEY key;
HANDLE regEvent;
DWORD previousStatus = 0;
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, L"System\\State\\Phone", 0, 0, 0, 0, 0, &key, 0)
!= ERROR_SUCCESS)
{
// can't create key
return 1;
}
regEvent = CeFindFirstRegChange(key, FALSE, REG_NOTIFY_CHANGE_LAST_SET);
if (regEvent == INVALID_HANDLE_VALUE)
{
// can't set up notification
RegCloseKey(key);
return 1;
}
while (true)
{
DWORD status, type, size;
if (WaitForSingleObject(regEvent, INFINITE) != WAIT_OBJECT_0)
{
// wait failed
break;
}
size = sizeof(status);
if (RegQueryValueEx(key, L"Status", 0, &type, (LPBYTE)&status, &size) ==
ERROR_SUCCESS)
{
// the registry change event is triggered if any value under
// HKEY_LOCAL_MACHINE\System\State\Phone has changed - verify if the Status
// value is different
if (status != previousStatus)
{
previousStatus = status;
// yes, Status has changed - this is the place to do "stuff" with it
}
}
CeFindNextRegChange(regEvent);
}
CeFindCloseRegChange(regEvent);
RegCloseKey(key);
return 0;
}
DWORD ThreadProc(LPVOID lpParam)
{
HKEY key;
HANDLE regEvent;
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, L"System\\State\\Phone", 0, 0, 0, 0, 0, &key, 0)
!= ERROR_SUCCESS)
{
// can't create key
return 1;
}
regEvent = CeFindFirstRegChange(key, FALSE, FILE_NOTIFY_CHANGE_CEGETINFO |
Comentarios a estos manuales