Programming Mobile Phones
by Panos Kougiouris

Listing One
import scm3as.*;
 ...
// Arrays because they are passed by reference (i.e. [out] parameters)
public String[] sIMEI = new String[1], sType = new String[1],
                             verSW = new String[1], verHW = new String[1];
 ...
IphoneBook2 m_pb = new PhonebookSuite3();
m_pb.GetDevIdentificationInfo(sIMEI, sType, verSW, verHW);


Listing Two
Variant vtEmpty = new Variant(""); vtEmpty.noParam();
    _Recordset rs = new Recordset();
    rs.getFields()._Append("Memory", DataTypeEnum.adBSTR, 100, 0);
    rs.getFields()._Append("Free", DataTypeEnum.adInteger, 4, 0);
    rs.getFields()._Append("Used", DataTypeEnum.adInteger, 4, 0);
    rs.getFields()._Append("Total", DataTypeEnum.adInteger, 4, 0);
    rs.getFields()._Append("NameLength", DataTypeEnum.adInteger, 4, 0);
    rs.getFields()._Append("PhoneLength", DataTypeEnum.adInteger, 4, 0);
    rs.setCursorLocation(CursorLocationEnum.adUseClient);
    rs.Open(vtEmpty, vtEmpty, CursorTypeEnum.adOpenStatic,
            LockTypeEnum.adLockBatchOptimistic,-1);
    m_cmdQueue.addCommand(new MemoryCommand(rs, m_pb), this,
            CommandsQueue.SYNCHRONOUS|CommandsQueue.DIALOGBOX);
    m_memDataGrid.setDataSource(new com.ms.wfc.data.Recordset(rs));


Listing Three
import scm3as.*;
import java.util.*;

public class ContactGroupsCommand extends Command {
    private IPhonebook2 m_pb;
    private String[] m_DefaultGroups = {"Family", "VIP", "Friends",
                                                     "Business", "Other"};
    public ContactGroupsCommand(IPhonebook2 pb){m_pb = pb;}
    public String getGroups()
    {
        String str = "";
        for (int i = 0; i < m_DefaultGroups.length; i++) {
            if (i != 0) str += ", ";
            str += (String)m_DefaultGroups[i];
        }
        return str;
    }
    public void executeInner() throws Throwable
    {
        for(int i = 0; i < 5; i++) {
            try {
                ICallerGroup grp = m_pb.GetCallerGroup(i);
                String name = grp.getName();
                if (name.length() != 0)
                    m_DefaultGroups[i] = name;
            } catch (Throwable thr) {
                int err = m_pb.GetLastError();
                if (err == NmpAdapterError.errPnInvalidMemory) continue;
                if (err == NmpAdapterError.errInvalidParameter) continue;
                throw thr;
            }
        }
    }
    public String getName()
    {
        return "Getting Groups...";
    }
}


Listing Four
private void m_btnDownload_click(Object source, Event e)
{
  m_cmdQueue.addCommand(new EraseAllCommand(m_pb), this,
        CommandsQueue.SYNCHRONOUS|CommandsQueue.DIALOGBOX);
  m_cmdQueue.addCommand(new DownloadContactsCommand(m_txtCategories.getText(),
        m_txtOutlookFolder.getText(), m_pb),
        this, CommandsQueue.SYNCHRONOUS|CommandsQueue.DIALOGBOX);
}


Listing Five
public void executeInner() throws Throwable
{
    Contacts m_contacts = new Contacts(m_groups, m_folderPath);
    Hashtable m_table = m_contacts.m_table;
    int j = 1;
    for (Enumeration e = m_table.keys(); e.hasMoreElements();) {
        String key = (String)e.nextElement();
        ContactInfo val = (ContactInfo)m_table.get(key);

        IContact contact = m_pb.CreateContact();
        contact.setName(key);
        contact.setNumber(val.m_number);
        contact.setMemory(PhonebookMemory.MEMORY_DEFAULT);
        contact.setGroupID(val.m_groupId);
        m_pb.SetContact(j, contact);
        j++;
    }
}
