locked
Probelm with Call History RRS feed

  • Question

  • Dear All,

     I am using Windows Mobile 6.0 SDK and Windows Mobile Professional Emulator to test my application and it is writtern in C#. I am writing an application which will read the call log and display the name,number and duration of the call in a list view.

     

    public class CALLLOGENTRY : IDisposable

    {

    public uint cbSize = (uint)Marshal.SizeOf(typeof(CALLLOGENTRY));

    public long ftStartTime = 0;

    public long ftEndTime = 0;

    public IOM iom = 0;

    public Flags flags = 0;

    public CALLERIDTYPE cidt = 0;

    public IntPtr pszNumber = IntPtr.Zero;

    public IntPtr pszName = IntPtr.Zero;

    public IntPtr pszNameType = IntPtr.Zero;

    public IntPtr pszNote = IntPtr.Zero;

    public enum CALLERIDTYPE

    {

    UNAVAILABLE,

    BLOCKED,

    AVAILABLE

    }

    public enum IOM

    {

    MISSED,

    INCOMING,

    OUTGOING

    }

    public enum Flags : byte

    {

    Outgoing = 0x1,

    Connected = 0x2,

    Ended = 0x4,

    Roam = 0x8

    }

    public enum CallerIDType

    {

    Unavailable,

    Blocked,

    Available

    }

    public enum CallType

    {

    Missed,

    Incoming,

    Outgoing

    }

    // Accessors

    public DateTime StartTime { get { return DateTime.FromFileTime(this.ftStartTime); } }

    public DateTime EndTime { get { return DateTime.FromFileTime(this.ftEndTime); } }

    public CallType CallTyp { get { return (CallType)this.iom; } }

    public bool Outgoing { get { return (this.flags & Flags.Outgoing) != 0; } }

    public bool Connected { get { return (this.flags & Flags.Connected) != 0; } }

    public bool Ended { get { return (this.flags & Flags.Ended) != 0; } }

    public bool Roam { get { return (this.flags & Flags.Roam) != 0; } }

    public CallerIDType CallerIDTyp { get { return (CallerIDType)this.cidt; } }

    public string Number { get { return Marshal.PtrToStringUni(this.pszNumber); } }

    public string Name { get{ return Marshal.PtrToStringUni(this.pszName); } }

    public string NameType { get { return Marshal.PtrToStringUni(this.pszNameType); } }

    public string NoteFile { get { return Marshal.PtrToStringUni(this.pszNote); } }

    /// <summary>

    /// Clean up string allocations.

    /// </summary>

    public void Dispose()

    {

    if (pszNumber != IntPtr.Zero)

    Memory.LocalFree(pszNumber);

    if (pszName != IntPtr.Zero)

    Memory.LocalFree(pszName);

    if (pszNameType != IntPtr.Zero)

    Memory.LocalFree(pszNameType);

    if (pszNote != IntPtr.Zero)

    Memory.LocalFree(pszNote);

    }

    }

     

    and i have a function to read and return all the call log entries

     

    public static CALLLOGENTRY[] GetCallLog()

    {

    IntPtr h = IntPtr.Zero;

    try

    {

    uint lastRecordIndex = 0;

    uint position = 0;

    CALLLOGENTRY[] entries = null;

    PhoneOpenCallLog(out h);

    if (h == IntPtr.Zero)

    return null;

    PhoneSeekCallLog(h, CALLLOGSEEK.END, 0, ref lastRecordIndex);

    entries = new CALLLOGENTRY[lastRecordIndex+1];

    for (uint i = 0; i <= lastRecordIndex; i++)

    {

    entriesIdea = new CALLLOGENTRY();

    PhoneSeekCallLog(h, CALLLOGSEEK.BEGINNING, i, ref position);

    PhoneGetCallLogEntry(h, entriesIdea);

    }

    return entries;

    }

    finally

    {

    if (h != IntPtr.Zero)

    PhoneCloseCallLog(h);

    }

    }

     

    Now when i dial a number in emulator and try to read it using this code it is able to detect the total number of calls in the log but the phone number is coming as 0, name is coming as null, iom is coming as MISSEDand all the data are wrong. What is wrong in the code?

     

    Thanks.

    Regards,

    Jeevanand.R

    Monday, February 11, 2008 8:35 AM

Answers

  • Dear Guang,

     Thanks for your reply. I have find out the solution the problem is with the class members now what i did is i created a structure

     

    [StructLayout(LayoutKind.Explicit, Size = 48)]

    private struct CALLLOGENTRY

    {

    [FieldOffset(0)]

    public uint cbSize;

    [FieldOffset(4)]

    public long ftStartTime;

    [FieldOffset(12)]

    public long ftEndTime;

    [FieldOffset(20)]

    public IOM iom;

    [FieldOffset(24)]

    public byte flags;

    [FieldOffset(28)]

    public CALLERIDTYPE cidt;

    [FieldOffset(32)]

    public IntPtr pszNumber;

    [FieldOffset(36)]

    public IntPtr pszName;

    [FieldOffset(40)]

    public IntPtr pszNameType;

    [FieldOffset(44)]

    public IntPtr pszNote;

    }

     

    and used it to read the data and i have a class which wraps the data. Now it is working fine.

     

    Regards,

    Jeevanand.

    Wednesday, February 13, 2008 4:11 AM

All replies

  • Hi Jeevanand.R,

    OpenNETCF has wrapped it, which provide the function to get call log , you can find it here. it can get call log easily:

    Code Snippet

    OpenNETCF.Phone.CallLog log = new OpenNETCF.Phone.CallLog();

    OpenNETCF.Phone.CallLogEntry entry=log.GetEntry();

     

     

     

    OpenNETCF wraps API you are invoking. You can also use Reflector to read the source code and refer to how it wrap the API and implement it.

     

    Best regards,

    Guang-Ming Bian - MSFT

    Wednesday, February 13, 2008 3:52 AM
  • Dear Guang,

     Thanks for your reply. I have find out the solution the problem is with the class members now what i did is i created a structure

     

    [StructLayout(LayoutKind.Explicit, Size = 48)]

    private struct CALLLOGENTRY

    {

    [FieldOffset(0)]

    public uint cbSize;

    [FieldOffset(4)]

    public long ftStartTime;

    [FieldOffset(12)]

    public long ftEndTime;

    [FieldOffset(20)]

    public IOM iom;

    [FieldOffset(24)]

    public byte flags;

    [FieldOffset(28)]

    public CALLERIDTYPE cidt;

    [FieldOffset(32)]

    public IntPtr pszNumber;

    [FieldOffset(36)]

    public IntPtr pszName;

    [FieldOffset(40)]

    public IntPtr pszNameType;

    [FieldOffset(44)]

    public IntPtr pszNote;

    }

     

    and used it to read the data and i have a class which wraps the data. Now it is working fine.

     

    Regards,

    Jeevanand.

    Wednesday, February 13, 2008 4:11 AM
  • Hey Jeevanand,

    I was wondering if you could post the working code. I would like to get the call history and have tried all sample codes available online without any luck. I would be truly appreciated.
    Thank you.





    Wednesday, September 10, 2008 3:05 AM