locked
how to set contact ringtone, WM sdk6 , WIN32 RRS feed

Answers

  • Hi rockerfeller8,


    IContact interface doesn't provide method to set ringtone value of a contact, but IItem provide the method, like the FAQ said, if IContact doesn't meet your requirements, you can consider IItem if the IItem interface has the method or property.
    How to retrieve a IM field data from a contact?

    We use IItem:: SetProps to set ringtone property. Here is a code sample, it is just a demo, it works fine in my local. But you have to modify it to suit your requirement:

    void CPOOMTestDlg::OnBnClickedButton5()

    {

            // TODO: Add your control notification handler code here

     

            CoInitializeEx( NULL, 0);

            IPOutlookApp2 * m_Outlook;

     

           

            HRESULT hr = CoCreateInstance(_uuidof(Application),

                          NULL,

                          CLSCTX_INPROC_SERVER,

                          _uuidof(IPOutlookApp),

                          (LPVOID*)&m_Outlook);

     

     

            m_Outlook->Logon(NULL);

     

            //Search contact only

            IFolder * pFolder=NULL;

            IPOutlookItemCollection *ipItemCollection=NULL;

            m_Outlook->GetDefaultFolder(OlDefaultFolders::olFolderContacts,&pFolder);

     

            int count=0;

            BSTR firstname;

            BSTR strIM;

            if(pFolder)

            {

                    pFolder->get_Items(&ipItemCollection);

                    if(ipItemCollection)

                    {

     

                            ipItemCollection->get_Count(&count);

     

                           

                            //get first contact information

                            IContact *pContact;

                            IItem *pItem;

                           

                            if (SUCCEEDED(ipItemCollection->Item(1,reinterpret_cast<IDispatch**>(&pContact))))

                            {

                                    CEOID oid = 0;

                                    pContact->get_Oid((long*)&oid);

                                    //get IItem interface

                                    m_Outlook->GetItemFromOidEx(oid, 0, &pItem);

                            }

     

                            //pItem->Edit(NULL);

            // TODO: Add your control notification handler code here

           

                             HRESULT hr                = E_FAIL;           

                             

                             CEPROPVAL  rgPropId[1];

                             rgPropId[0].propid=PIMPR_RINGTONE;

                             rgPropId[0].val.lpwstr=L"song name";

                           

                             hr=pItem->SetProps(0,1,rgPropId);

     

                             hr=pItem->Save();     

                           

                           

                            pContact->Release();

                pContact = NULL;

                            pItem->Release();

                            pItem=NULL;

                           

     

     

                    }

            }

     

                    ipItemCollection->Release();

                    ipItemCollection=NULL;

                    pFolder->Release();

            pFolder = NULL;

                    m_Outlook->Logoff();

            m_Outlook->Release();

            m_Outlook = NULL;

    }


    Please note the red code, it do the work of set ringtone value.


    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Monday, September 7, 2009 7:28 AM