Please enable javascript for this site to work

Getting Call Logs

Most of the people today choose powerful pda's or others that have extended programming ability as a phone.

As i am developing a finger friendly user interface (iphone like) to my pda (which has a windows mobile 2003 se OS), i did som research on google on google to find out, how to fetch data from many components of the phone programmatically.

First thing i will talk about Mobile Programming on PDA, how to fetch recent call history from WM2003 device (and possibly from WM5.0,6.0,6.1 devices).

To fetch call logs we will use "phone.h" header provided with Windows Mobile SDK.(By the way click plus sign to extend code)

Code: c
  1. std::vector<PCALLLOGENTRY> lst;
  2. HANDLE ph = NULL;
  3. HRESULT result;
  4. DWORD lastEntryIndex = 0;
  5. DWORD currentEntryIndex = 0;
  6.  
  7. result = PhoneOpenCallLog(&ph);
  8. if(result == E_FAIL)
  9. return lst;
  10.  
  11. result = PhoneSeekCallLog(ph, CALLLOGSEEK_END, 0, &lastEntryIndex);
  12. if (result == E_FAIL)
  13. {
  14. DWORD err = GetLastError();
  15. PhoneCloseCallLog(ph);
  16. return lst;
  17. }
  18.  
  19. result = PhoneSeekCallLog(ph, CALLLOGSEEK_BEGINNING,
  20. 0, &currentEntryIndex);
  21. if (result == E_FAIL)
  22. {
  23. PhoneCloseCallLog(ph);
  24. return lst;
  25. }

At this code we get our call log handle with "PhoneOpenCallLog". Since windows mobile api is mostly written in c like style, we have to pass this handle to other phone functions. If function fails we simply return.

After getting handle we try to get last index with function "PhoneSeekCallLog". As you can see like the most of the other windows api functions, we send the HANDLE value. Again we have to check errors if something bad happens.

To get current(start) position of the index, again we use the same function with CALLLOGSEEK_BEGINNING parameter.

Since we got our starting and ending index now we can get our call history in a 'for' loop.

Code: c
  1. for(DWORD i = 0; i <= lastEntryIndex; i )
  2. {
  3. PCALLLOGENTRY call = new CALLLOGENTRY();
  4. call->cbSize = sizeof(CALLLOGENTRY);
  5.  
  6. result = PhoneGetCallLogEntry(ph, call);
  7. if(result == E_FAIL)
  8. {
  9. PhoneCloseCallLog(ph);
  10. return lst;
  11. }
  12. lst.push_back(call);
  13. }

Since we seek to the first value with this handle before, now we can loop and get all the call logs. "PhoneGetCallLogEntry" don't get the parameter of index value. It increments the position at background somewhere inside winapi with handle. Since call log is a database on phone (which is clog.db), It simple wraps user from working with offsets of the database.

We are setting size parameter of the CALLLOGENTRY format because, in future versions of the Windows Mobile, size of the CALLLOGENTRY might change and this will give us the compability without changing code.

Code: c
  1. typedef struct
  2. {
  3. DWORD cbSize; // sizeof CALLLOGENTRY
  4. FILETIME ftStartTime;
  5. FILETIME ftEndTime;
  6. IOM iom;
  7. BOOL fOutgoing:1; // direction of call. (Missed calls are incoming.)
  8. BOOL fConnected:1; // Did the call connect? (as opposed to busy, no answer)
  9. BOOL fEnded:1; // Was the call ended? (as opposed to dropped)
  10. BOOL fRoam:1; // Roaming (vs. local)
  11. CALLERIDTYPE cidt;
  12. PTSTR pszNumber;
  13. PTSTR pszName;
  14. PTSTR pszNameType; // "w" for work tel, "h" for home tel, for example
  15. PTSTR pszNote; // filename of associated Notes file
  16. } CALLLOGENTRY, *PCALLLOGENTRY;

Here we see the contents of the struct, when we look at the msdn reference, it indicates that

Quote From: Microsoft

cbSize

The size of the CALLLOGENTRY structure. The value of this member must be set to sizeof CALLLOGENTRY before the PhoneGetCallLogEntry function is called.

ftStartTime

The start time of the logged call.

ftEndTime

The end time of the logged call.

iom

Indicates whether the call was missed (incoming), answered (incoming), or outgoing. This member contains one of the values in the IOM enumeration.

fOutgoing:1

Indicates the direction of the call (missed calls are incoming).

fConnected:1

Indicates whether the call connected (as opposed to a busy signal or no answer).

fEnded:1

Indicates whether the call ended (as opposed to being dropped).

fRoam:1

Indicates whether the call was made while roaming (as opposed to a call made within the home service area).

cidt

The caller ID type. This member contains one of the values in the CALLERIDTYPE enumeration.

pszNumber

Pointer to the telephone number of the call.

pszName

Pointer to the name associated with the call.

pszNameType

Pointer to the name type associated with the call. For example, "w" would correspond with the work telephone number, "h" would correspond with the home telephone number, and so on.

pszNote

Pointer to the file name of the Notes file associated with the call (if a Notes file exists).

PTSTR is simply constant TCHAR pointer which is,

If UNICODE defined WCHAR(wide char), if not defined CHAR(ascii char) pointer. You can print it with

Code: c
  1. std::vector<PCALLLOGENTRY> lst = GetCallLogs();
  2. PCALLLOGENTRY pcle = lst[0];
  3. printf("%s", pcle->pszName);

With these article now you can fetch recent call list.

Have fun

0 comments

1
 

You need Flash for this. Get the latest version from here.