From: Miky on
Dear All,

First I want to thank the Forum.... it is very important for we
programmers....

This is my question....

How do I delete a SMS with CEMAPI functions ?

I read on MSDN of DeleteMessages but I not understood..... Can I help ?

Miky

Here's my code:

while (TRUE)

{

// Free the previous row

FreeProws (prowset);

prowset = NULL;



hr = ptbl->QueryRows (1, 0, &prowset);

if ((hr != S_OK) || (prowset == NULL) ||
(prowset->cRows == 0))

return -1;



ASSERT (prowset->aRow[0].cValues == spta.cValues);

SPropValue *pval = prowset->aRow[0].lpProps;



ASSERT (pval[0].ulPropTag == PR_DISPLAY_NAME);

ASSERT (pval[1].ulPropTag == PR_ENTRYID);



if (!_tcscmp(pval[0].Value.lpszW, TEXT("SMS")))

{

// Get the Message Store pointer

hr = pSession->OpenMsgStore(0,
pval[1].Value.bin.cb, (LPENTRYID)pval[1].Value.bin.lpb, 0, 0, &pStore);



/**********************/

static const SizedSSortOrderSet(1,
sortOrderSet) = { 1, 0, 0, { PR_MESSAGE_DELIVERY_TIME,
TABLE_SORT_DESCEND } };

static const SizedSPropTagArray (3,
spta) = { 3, PR_SENDER_NAME, PR_SUBJECT, PR_MESSAGE_DELIVERY_TIME };

HRESULT hr = S_OK;

LPENTRYID pEntryId = NULL;

ULONG cbEntryId = 0;

CComPtr <IMAPIFolder>pFolder;

CComPtr <IMAPITable>ptbl;

ULONG ulObjType = 0;

SRowSet *prowset = NULL;



// Get the inbox folder

hr = pStore->GetReceiveFolder(NULL,
MAPI_UNICODE, &cbEntryId, &pEntryId, NULL);



// 2 we have the entryid of the inbox
folder, let's get the folder and messages in it

hr = pStore->OpenEntry(cbEntryId,
pEntryId, NULL, 0, &ulObjType, (LPUNKNOWN*)&pFolder);



// 3 From the IMAPIFolder pointer,
obtain the table to the contents

hr = pFolder->GetContentsTable(0,
&ptbl);



// 4 Sort the table that we obtained.
This is determined by the sortOrderSet variable

hr = ptbl->SortTable((SSortOrderSet
*)&sortOrderSet, 0);



// 5 Set the columns of the table we
will query. The columns of each row are determined by spta

hr = ptbl->SetColumns ((SPropTagArray *)
&spta, 0);



// now get first message in the table

// Free the previous row

FreeProws (prowset);

prowset = NULL;



hr = ptbl->QueryRows (1, 0, &prowset);

if ((hr != S_OK) || (prowset == NULL) ||
(prowset->cRows == 0))

return -1;



ASSERT (prowset->aRow[0].cValues ==
spta.cValues);

SPropValue *pval =
prowset->aRow[0].lpProps;



// 6 Get the three properties we need:
Sender name, Subject, and Delvery time.

ASSERT (pval[0].ulPropTag ==
PR_SENDER_NAME);

ASSERT (pval[1].ulPropTag ==
PR_SUBJECT);

ASSERT (pval[2].ulPropTag ==
PR_MESSAGE_DELIVERY_TIME);



LPCTSTR pszSender = pval[0].Value.lpszW;

LPCTSTR pszSubject =
pval[1].Value.lpszW;

SYSTEMTIME st = {0};

FileTimeToSystemTime(&pval[2].Value.ft,
&st);



// 7 Pass the parameters to a function
to archive (this function is not written)

//hr = AppendToFile(pszFilename,
pszSender, pszSubject, st);

if ( !_tcscmp(pval[1].Value.lpszW,
TEXT("1100")) )

{

// 7 Pass the parameters to a
function to archive (this function is not written)

//hr = AppendToFile(pszFilename,
pszSender, pszSubject, st);

AfxMessageBox(pszSender);

AfxMessageBox(pszSubject);



here after read SMS ---> delete the message

How?



//SBinary id = {
entry.arrId.GetSize(), (BYTE*)entry.arrId.GetData() };

//ENTRYLIST ls = { 1, &id };

//HRESULT hr =
pFolder->DeleteMessages(&ls, 0, NULL, 0);









}



/**********************/

}