Click here to Skip to main content
15,899,314 members
Articles / Mobile Apps / Windows Mobile

Sending an SMS using CEMAPI

Rate me:
Please Sign up or sign in to vote.
4.67/5 (17 votes)
13 Sep 2004CPOL3 min read 222K   1.4K   58   74
How to send an SMS using the CEMAPI APIs.

Sample Image - main.gif

Introduction

If you have not got a Pocket PC Phone Edition or Windows CE SmartPhone device, sorry this article will not be useful.

Now having got that out of the way, this article will show how to send an SMS to another SMS capable device, using the Windows CE MAPI API (A.K.A. CEMAPI) instead of the supplied SMS APIs.

Background

SMS or Simple Messaging Service is a means of sending a short message (160 characters max) to another SMS capable device via the GSM network. On Pocket PC Phone edition devices and Windows CE Smart phones, when selecting a folder, there should have been at least an ActiveSync and SMS message store and possibly an MMS message store as well.

These message stores hold messages from different transport providers locally on the device.

For the purposes of this article, we will be concentrating on the SMS message store as we want to use this to send a message.

Using the code

To make the code simpler and easier to understand, the bulk of the code uses MFC for the User Interface and ATL for smart pointer support.

If people request it, I may make a Win32 only version available as the relevant code (i.e., not the UI code) only requires ATL and not MFC.

In this article, I am not going through a listing of the creation of the MAPI session and opening of the SMS message store and outbox folder. The code is well commented and provided in the source zip file in the two functions GetSMSMsgStore and GetSMSFolder which get the relevant SMS message store and the SMS drafts folder.

So we start looking at the code when we have created a new message in the Outbox folder.

The bulk of the code involves creating the recipients and setting the sender and message status.

First is setting the recipient of the message. To make the code clearer, I have only set one recipient on for the message, although multiple recipients may be set, each one requiring three properties, the type of recipient, the type of address, and the email address.

Unfortunately, I found the code that Microsoft provided for the MAPI samples too complex as they were overshadowed by overly complex memory and pointer manipulation. To that end, I have provided a simpler implementation for recipients.

First, we create the properties that we need for a recipient.

SPropValue propRecipient[3];
ZeroMemory(&propRecipient, sizeof(propRecipient));
// set the recipient type which coul be to, cc, bcc
// but there must at least be a to field then the
propRecipient[0].ulPropTag = PR_RECIPIENT_TYPE;
propRecipient[0].Value.l = MAPI_TO;
propRecipient[1].ulPropTag = PR_ADDRTYPE;
propRecipient[1].Value.lpszW = _T("SMS");
propRecipient[2].ulPropTag = PR_EMAIL_ADDRESS;
propRecipient[2].Value.lpszW = (LPWSTR)lpszTo;

If you want to add additional recipients to the message, you can expand the propRecipient to a multiple of three, and add the appropriate recipient type, address type, and address properties.

Next, the ADRLIST structure needs to be set with pointers to the recipient properties and the count of the properties. You will need to provide one ADRENTRY per recipient.

// we create the addlist structure and set it to point to the recipient
// properties
    ADRLIST adrlist;
    adrlist.cEntries = 1;
    adrlist.aEntries[0].cValues = 3;
    adrlist.aEntries[0].rgPropVals = (LPSPropValue)(&propRecipient);

    // finally modify the recipients of the message
    hr = spMessage->ModifyRecipients(MODRECIP_ADD, &adrlist);

Finally, we set the subject of the message as the text of the SMS body to be sent. Note that the length of the SMS message can be no longer than 160 characters as this is the maximum size of a message that can be sent using the GSM Short Messaging Service.

Lastly, we set the remainder of the properties, which are the sender as the person originating the message, and the message record type to SMS so that is gets enumerated by the transport and get sent correctly. Optionally, the message can have the message flags set which indicate that the message is unsent and originates from me.

SPropValue props[4];
ZeroMemory(&props, sizeof(props));
// set the subject
props[0].ulPropTag = PR_SUBJECT;
props[0].Value.lpszW = (LPWSTR)lpszMessage;
//Set the sender
props[1].ulPropTag = PR_SENDER_EMAIL_ADDRESS;
props[1].Value.lpszW = (LPWSTR)lpszFrom;
//Set the message status to indicate this message needs
//enumeration. Vital property!
props[2].ulPropTag = PR_MSG_STATUS;
props[2].Value.ul = MSGSTATUS_RECTYPE_SMS;
// Optional flags property for the message flags
// Seems to work okay without these being set
props[3].ulPropTag = PR_MESSAGE_FLAGS;
props[3].Value.ul = MSGFLAG_FROMME | MSGFLAG_UNSENT;
// Finally set the properties on the message
hr = spMessage->SetProps(sizeof(props) / sizeof(props[0]), 
                             (LPSPropValue)&props, NULL);

As all the properties and recipients have now been set on the message, it is safe to call SubmitMessage.

//Submit the new message to the message store so that it may be submitted to the 
appropriate message transport provider.

hr = spMessage->SubmitMessage(0);

If you wait a couple of seconds, the message will appear on the phone number you specified in the To field of the message. Also note that the sent message will now appear in the Sent Items folder as you would expect.

I have not included a Win32 or SmartPhone version of the code here at the moment. However, if anyone wants versions of it, email me and I will consider updating the samples to include SmartPhone and a pure Win32 version.

Points of Interest

None

History

No revisions thus far.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
I make computers talk to other computers - well thats that I tell everyone I do. What I really do is connectivity and syncronization software for Windows Ce, PalmOS, Symbian on client devices and MFC/ATL/.NET on the Windows Servers.

I am also an expert with Microsoft Exchange and Databases and pretty good with Lotus Notes as well.

Comments and Discussions

 
GeneralRe: Has anyone tried sending MMS msg using MAPI? Pin
merchecaso26-Jul-06 23:16
merchecaso26-Jul-06 23:16 
GeneralSending MMS Pin
hira_mannan16-Apr-05 5:09
hira_mannan16-Apr-05 5:09 
Generalcheck received message Pin
lvguangchuan14-Mar-05 16:28
lvguangchuan14-Mar-05 16:28 
GeneralRe: check received message Pin
EK_Kiwi30-May-05 20:42
EK_Kiwi30-May-05 20:42 
QuestionMessage to the subject? Pin
kurtak16-Feb-05 8:48
kurtak16-Feb-05 8:48 
AnswerRe: Message to the subject? Pin
HuangGX16-Feb-05 11:13
HuangGX16-Feb-05 11:13 
AnswerRe: Message to the subject? Pin
guest coder30-Mar-06 1:38
guest coder30-Mar-06 1:38 
QuestionUn-recognizied characters when sending SMS by CEMAPI?? Pin
HuangGX15-Feb-05 7:00
HuangGX15-Feb-05 7:00 
Hi EK_Kiwi

I am here because I have googled "SMS MAPI".
I am tring to write a SMS program by using CeMAPI. Why?
Because the SMS API can only send SMS messages, but could NOT act as the built-in SMS program -- it won't store SMS messages in SMS store/folders.

the code i used is originally from MSDN website (named SendMail, it is also with eVC++ 4.0 installation). I only changed two places: PR_ADDRTYPE to L"SMS", PR_MSG_STATUS to MSGSTATUS_RECTYPE_SMS. Someone in the net said that, the PR_MESSAGE_CLASS should be set as "IPM.SMStext" (in ASCII string, not unicode).

I tried them all, and I can send out SMS messages, but has problems:
1, the Chinese text in the SMS message sent by my program is un-recognized, they appear as ???????, one ? for each Chinese character. BUT, in the SentBox(of my Chinese verion of XDAII), every thing is ok.
2, after I run my program, the built-in SMS program act strangely: when compose an SMS message, there will be Cc, Bcc and Subject fields!!! They should be something related to eMail message, but not SMS message. Is this caused by my earlier testing (first time I compiled my program and download to my XDAII, MGS_STATUS was not set to MSGSTATUS_RECTYPE_SMS. so it changed my SMS message store's properties?)?

3, IYO, do you think it is mecessary to set PR_MESSAGE_CLASS as "IPM.SMStext"? I didn't find any change.

Please help me.

here is my code
============================================================
/*
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

This is sample code and is freely distributable.
*/

#include <mapidefs.h>
#include <mapicode.h>
#include <mapitags.h>
#include <mapix.h>
#include <mapiutil.h>
#include <cemapi.h>

//Macros
#ifndef EXIT_ON_FAILED
#define EXIT_ON_FAILED(_hr)\
if (FAILED(_hr))\
{ \
RETAILMSG(1,(_T("CEMAPI: FAILED(%x)at %hs:%d\n"), \
_hr, __FILE__, __LINE__)); \
goto FuncExit; \
}
#endif //EXIT_ON_FAILED

#ifndef RELEASE_OBJ
#define RELEASE_OBJ(s)\
if (s != NULL)\
{ \
s->Release(); \
s = NULL; \
}
#endif //RELEASE_OBJ

//Function Prototypes
HRESULT CEMAPI_SetMessageRecipients(LPMESSAGE pmsg);
HRESULT CEMAPI_SetMessageProps(LPMESSAGE pmsg);
void CEMAPI_AddRecipients(LPWSTR pszSrc, ULONG ulType, ADRLIST* plst,
LPWSTR& pszLocalRecips, LPSPropValue& pval);
ULONG CountRecipsInString(LPCWSTR psz);
HRESULT CEMAPI_AttachFile(LPMESSAGE pmsg);


// **************************************************************************
// Function Name: WinMain
// Purpose: Standard Win32 entry point

// Arguments:
// none are used for this sample
//
// Return Values:
// int
// app exit code
//
// Description:
//
// This function controls the main flow of the application. A summary:
// Logon to the message store
// Get the message stores table
// For each entry(i.e. local account)
// Open current store entry
// Get the Drafts folder(necessary for outgoing mail)
// Create a new message in this folder
// Set relevant message properties(Recipients, Subject, Body, etc)
// Send the message
// Clean up
//


int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int CmdShow
)
{

HRESULT hr;
IMAPISession * pSession = NULL;
IMAPITable * pTable = NULL;
SRowSet * psrs = NULL;
IMsgStore * pStore = NULL;
ULONG rgTags[] = { 1, PR_CE_IPM_DRAFTS_ENTRYID };

ULONG cValues = 0;
SPropValue * rgprops = NULL;
SPropValue * rgpropsMsg = NULL;
LPMAPIFOLDER pfldrDrafts = NULL;
IMessage * pmsg = NULL;


// First logon to the store.
hr = MAPILogonEx(NULL, NULL, NULL, NULL, &pSession);
EXIT_ON_FAILED(hr);


// Get the message stores table
hr = pSession->GetMsgStoresTable(MAPI_UNICODE, &pTable);
EXIT_ON_FAILED(hr);


while (SUCCEEDED(pTable->QueryRows(2, 0, &psrs))) //原来第一个参数是1
{
// Check number of rows returned. Since the above call only asks for
one,
// anything else means we are at the end of the table
if (0 == psrs->cRows)
{
//MessageBox(NULL, L"Qery!", L"Error", MB_OK);
break;
}


// Make sure we got the props we need
if ((1 > psrs->aRow[1].cValues)||(PR_ENTRYID !=
psrs->aRow[1].lpProps[0].ulPropTag))
{
MessageBox(NULL, L"Store missing PR_ENTRYID!", L"Error", MB_OK);
hr = E_FAIL;
break;
}

// Open this message store
hr = pSession->OpenMsgStore(NULL,
psrs->aRow[1].lpProps[0].Value.bin.cb,
(ENTRYID *)psrs->aRow[1].lpProps[0].Value.bin.lpb , //bin.lpb,
NULL,
0,
&pStore);
EXIT_ON_FAILED(hr);

// Now get the Drafts folder. In order for a message to be sent by
MAPI, it must be created
// in the Drafts folder
hr = pStore->GetProps((SPropTagArray *)rgTags, MAPI_UNICODE,
&cValues, &rgprops);
EXIT_ON_FAILED(hr);

ASSERT(rgprops);
ASSERT(rgprops[0].ulPropTag == PR_CE_IPM_DRAFTS_ENTRYID);


hr = pStore->OpenEntry(rgprops[0].Value.bin.cb,
(LPENTRYID)rgprops[0].Value.bin.lpb , //bin.lpb,
NULL,
MAPI_MODIFY,
NULL,
reinterpret_cast <iunknown **="">(&pfldrDrafts));
EXIT_ON_FAILED(hr);

ASSERT(pfldrDrafts);


// Now create a message...
hr = pfldrDrafts->CreateMessage(NULL, 0, &pmsg);
EXIT_ON_FAILED(hr);

ASSERT(pmsg);

// MessageBox(NULL, L"短信已经生成!", L"Error", MB_OK);
// Now set the some properies on the message....
CEMAPI_SetMessageProps(pmsg);

// attach a bogus file
//MessageBox(NULL, L"短信属性!", L"Error", MB_OK);
//hr=CEMAPI_AttachFile(pmsg);
//EXIT_ON_FAILED(hr);

// Now send the message
hr = pmsg->SubmitMessage(0);
EXIT_ON_FAILED(hr);
MessageBox(NULL, L"短信已经发送!", L"Error", MB_OK);

// Clean up
MAPIFreeBuffer(rgprops);
MAPIFreeBuffer(rgpropsMsg);
FreeProws(psrs);

rgprops = NULL;
rgpropsMsg = NULL;
psrs = NULL;

RELEASE_OBJ(pmsg);
RELEASE_OBJ(pfldrDrafts);
RELEASE_OBJ(pStore);
}


FuncExit:
//Clean up
MAPIFreeBuffer(rgprops);
MAPIFreeBuffer(rgpropsMsg);
FreeProws(psrs);

RELEASE_OBJ(pmsg);
RELEASE_OBJ(pfldrDrafts);
RELEASE_OBJ(pStore);
RELEASE_OBJ(pTable);
RELEASE_OBJ(pSession);


return 0;

}


// **************************************************************************
// Function Name: CountRecipsInString
// Purpose: Counts the number of recipient addresses in a given string

// Arguments:
// IN LPCWSTR psz - string of recipients
//
// Return Values:
// ULONG
// Count of recipients(number of semi-colons + 1)contained in the input
string
//
// Description:
//
// This function merely counts the number of semi-colons in a string and
returns that
// number + 1. This can be interpreted as the number of recipients in a
properly formatted
// recipient list
//


ULONG CountRecipsInString(
LPCWSTR psz
)
{
ULONG cRecips = 0;

if (psz != NULL)
{
if (*psz != '\0')
{
++cRecips;
}

while (*psz != L'\0')
{
if (*psz == L';')
{
++cRecips;
}
++psz;
}
}

return cRecips;
}

// **************************************************************************
// Function Name: CEMAPI_AddRecipients
// Purpose: Sets a message's recipient(s)to a hard-coded value

// Arguments:
// IN LPWSTR pszSrc - semi-colon delimited recipient list
// IN ULONG ulType - Recipient type(To, Cc, or Bcc)
// INOUT ADRLIST* plst - Recipient buffer, pointer is incremented and returned
// IN LPWSTR pszLocalRecips& - local copy of pszSrc
// INOUT LPSPropValue& - buffer to hold message props(address type, recip
type, etc),
// incremented and returned
//
// Return Values:
// void
//
// Description:
//
// This function sets recipient properties for a list of recipients.
Properties include
// the recipient type(To, Cc, or Bcc), the address type(always SMTP), and
the e-mail
// address list. The properties are returned through the plst parameter.
//


void CEMAPI_AddRecipients(
LPWSTR pszSrc,
ULONG ulType,
ADRLIST* plst,
LPWSTR& pszLocalRecips,
LPSPropValue& pval
)
{
if (pszSrc == NULL)
{
return;
}

LPWSTR psz = pszSrc;
while (*psz != L'\0')
{
while (*psz == L' ' && *psz != '\0')
{
++psz;
}

if (*psz == L'\0')
{
break;
}

LPWSTR pszEnd = psz;
while (*pszEnd != L' ' && *pszEnd != ';' && *pszEnd != '\0')
{
++pszEnd;
}

int cch = pszEnd - psz;

wcsncpy(pszLocalRecips, psz, cch);
*(pszLocalRecips + cch)= L'\0';

plst->aEntries[plst->cEntries].cValues = 3;
plst->aEntries[plst->cEntries].rgPropVals = pval;

// Set the type(To, Cc, Bcc)...
pval->ulPropTag = PR_RECIPIENT_TYPE;
pval->Value.ul = ulType;
++pval;

// Set the address type(SMTP is the only type currently supported)
pval->ulPropTag = PR_ADDRTYPE;
pval->Value.lpszW = L"SMS"; //SMTP
++pval;

// Set the address...
pval->ulPropTag = PR_EMAIL_ADDRESS;
pval->Value.lpszW = pszLocalRecips;
++pval;

++plst->cEntries;

pszLocalRecips += wcslen(pszLocalRecips)+ 1;

if (*pszEnd != L'\0')
{
++pszEnd;
}

psz = pszEnd;
}
}



// **************************************************************************
// Function Name: CEMAPI_SetMessageRecipients
// Purpose: Sets a message's recipient(s)to a hard-coded value

// Arguments:
// INOUT LPMESSAGE pmsg - pointer to IMessage interface
//
// Return Values:
// HRESULT
// returns S_OK if the message's recipients are successfully modified.
Otherwise an error
// is returned
//
// Description:
//
// This function defines a hard-coded string which represents the recipients
for the given
// message. The list of recipients is semi-colon delimited. The string for
each field(To,
// Cc, and Bcc)is parsed and a count of recipients is calculated. A buffer
is allocated
// to hold the list of recipients. The recipients are added to the the
buffer by field type,
// and the the buffer is passed into IMessage::ModifyRecipients.

HRESULT CEMAPI_SetMessageRecipients(
LPMESSAGE pmsg
)
{
ULONG cRecipients = 0;
ULONG cchTotalRecips = 0;

//hard-coded recip values. Delimit with semi-colons if more than address is
used per field
//Example: LPWSTR pszTo = L"foo@bar.com;test@bar.com";
LPWSTR pszTo = L"13911822618";
LPWSTR pszCc = L"";
LPWSTR pszBcc = L"";
ADRLIST* plst = NULL;
LPSPropValue pval = NULL;
BYTE* pb = NULL;
LPWSTR pszLocalRecips;
HRESULT hr;

if (pszTo)
{
cRecipients += CountRecipsInString(pszTo);
cchTotalRecips += wcslen(pszTo)+ 3;
}

/* if (pszCc)
{
cRecipients += CountRecipsInString(pszCc);
cchTotalRecips += wcslen(pszCc)+ 3;
}

if (pszBcc)
{
cRecipients += CountRecipsInString(pszBcc);
cchTotalRecips += wcslen(pszBcc)+ 3;
}
*/
//
// Allocate one big block of memory to hold all the strings.
// The block is arranged as follows:
//
// ADRLIST SPropValue's Copy of addresses
// |---------------------|--------------------|---------------------|
//

DWORD cb = sizeof(ADRLIST)+((sizeof(ADRENTRY)+ sizeof(SPropValue)* 3)*
cRecipients);

pb = new BYTE[cb +(cchTotalRecips * sizeof(WCHAR))];
if (pb == NULL)
{
return E_OUTOFMEMORY;
}

ZeroMemory(pb, cb +(cchTotalRecips * sizeof(WCHAR)));

plst =(ADRLIST*)pb;

pszLocalRecips =(LPWSTR)(pb + cb);

pb += sizeof(ADRLIST)+(sizeof(ADRENTRY)* cRecipients);

pval =(SPropValue*)pb;

CEMAPI_AddRecipients(pszTo, MAPI_TO, plst, pszLocalRecips, pval);
// CEMAPI_AddRecipients(pszCc, MAPI_CC, plst, pszLocalRecips, pval);
// CEMAPI_AddRecipients(pszBcc, MAPI_BCC, plst, pszLocalRecips, pval);

hr = pmsg->ModifyRecipients(MODRECIP_ADD, plst);

delete[](BYTE*)plst;

return hr;
}



// **************************************************************************
// Function Name: CEMAPI_SetMessageProps
// Purpose: Sets some hardcoded properties on a given message

// Arguments:
// INOUT LPMESSAGE pmsg - pointer to IMessage interface
//
// Return Values:
// HRESULT
// returns S_OK if the properties are successfully set, otherwise an
error is returned
//
// Description:
//
// This function sets up message recipients, sets the message properties,
then writes the
// the message body to the message via an IStream interface.

HRESULT CEMAPI_SetMessageProps(
LPMESSAGE pmsg
)
{
SPropValue rgprops[4] = {0};
ULONG cProps = 0;
HRESULT hr;
TCHAR pszSubject[] = L"";
TCHAR pszBody[] = L"短信内容."; //********* it is in Chinese!
LPSTREAM pstm = NULL;
unsigned long test;
char test1[] = "IPM.SMStext";
//test = (unsigned long) &test1;

// Set the recipients up.
hr = CEMAPI_SetMessageRecipients(pmsg);
EXIT_ON_FAILED(hr);

// Set the flags and a subject if they exist.
//rgprops[cProps].ulPropTag = PR_MESSAGE_FLAGS;
//rgprops[cProps].Value.ul = MSGFLAG_UNSENT;
//++cProps;

// rgprops[cProps].ulPropTag = PR_LANGUAGE;
// rgprops[cProps].Value.lpszA = "cn"; //"IPM.SMStext";
// ++cProps;

rgprops[cProps].ulPropTag = PR_MESSAGE_CLASS;
rgprops[cProps].Value.lpszA = "IPM.SMStext";
++cProps;

rgprops[cProps].ulPropTag = PR_MSG_STATUS;
rgprops[cProps].Value.ul = MSGSTATUS_RECTYPE_SMS; //SMTP;
++cProps;

rgprops[cProps].ulPropTag = PR_MESSAGE_FLAGS;
rgprops[cProps].Value.ul = MSGFLAG_UNSENT;
++cProps;

if (pszSubject != NULL)
{
rgprops[cProps].ulPropTag = PR_SUBJECT;
rgprops[cProps].Value.lpszW = pszSubject;
++cProps;
}

// Apply the property values to this message
hr = pmsg->SetProps(cProps, rgprops, NULL);
EXIT_ON_FAILED(hr);

// Stream the body in...
hr = pmsg->OpenProperty(PR_BODY, NULL, STGM_WRITE, MAPI_MODIFY,
(LPUNKNOWN*)&pstm);
EXIT_ON_FAILED(hr);

pstm->Write(pszBody,(wcslen(pszBody)+ 0)* sizeof(WCHAR), NULL);
pstm->Release();

FuncExit:
return hr;
}

// **************************************************************************
// Function Name: CEMAPI_AttachFile
// Purpose: Attaches a bogus file to the outgoing message

// Arguments:
// INOUT LPMESSAGE pmsg - pointer to IMessage interface
//
// Return Values:
// HRESULT
// returns S_OK if the "file" is successfully attached, otherwise an
error is returned
//
// Description:
//
// This function sets up a file attachment and associates it with the
specified message,
// and reads in the file data from via IStream. The "file" in this example
is just dummy
// data. Normally data from a real file would be streamed in and written to
the attachment.

HRESULT CEMAPI_AttachFile(
LPMESSAGE pmsg
)
{
IAttach * pAttachment = NULL;
SPropValue rgpropsAttch[3];
ULONG ulAttachNum;
HRESULT hr;
// bogus filename...normally would reference a real file
WCHAR wcsAttachmentName[] = L"test.txt";
DWORD dwFileSize;
ULONG ulStatus = MSGSTATUS_RECTYPE_SMTP;
IStream * pstmAttachment = NULL;
// our fake file data, normally would be streamed in from a file
char szBuf[] = "Hello, Windows CE";


dwFileSize = strlen(szBuf)+1;
// create the attachment
hr = pmsg->CreateAttach(NULL, 0, &ulAttachNum, &pAttachment);
EXIT_ON_FAILED(hr);

rgpropsAttch[0].ulPropTag = PR_ATTACH_FILENAME;
rgpropsAttch[0].Value.lpszW = wcsAttachmentName;

rgpropsAttch[1].ulPropTag = PR_ATTACH_SIZE;
rgpropsAttch[1].Value.ul = dwFileSize;

rgpropsAttch[2].ulPropTag = PR_MSG_STATUS;
rgpropsAttch[2].Value.ul = ulStatus;

hr = pAttachment->SetProps(sizeof(rgpropsAttch)/
sizeof(rgpropsAttch[0]), rgpropsAttch, NULL);
EXIT_ON_FAILED(hr);

// open a stream on the attachment
hr = pAttachment->OpenProperty(PR_ATTACH_DATA_BIN, NULL
/*&IID_IStream*/, STGM_WRITE, MAPI_MODIFY,
reinterpret_cast <iunknown
**="">(&pstmAttachment));
EXIT_ON_FAILED(hr);

// store chunk from our fake file buffer into the stream
hr = pstmAttachment->Write(szBuf, 5, NULL);
EXIT_ON_FAILED(hr);

// commit it
hr = pstmAttachment->Commit(STGC_DEFAULT);
EXIT_ON_FAILED(hr);


FuncExit:
MAPIFreeBuffer(rgpropsAttch);
RELEASE_OBJ(pAttachment);
RELEASE_OBJ(pstmAttachment);
return hr;

}



============================================================
AnswerRe: Un-recognizied characters when sending SMS by CEMAPI?? Pin
HuangGX15-Feb-05 7:04
HuangGX15-Feb-05 7:04 
GeneralRe: Un-recognizied characters when sending SMS by CEMAPI?? Pin
nbcool25-Sep-05 2:47
nbcool25-Sep-05 2:47 
GeneralStarting Pocket Outlook Pin
Larsa31-Jan-05 3:26
Larsa31-Jan-05 3:26 
GeneralRe: Starting Pocket Outlook Pin
turbozv24-Jan-06 21:24
turbozv24-Jan-06 21:24 
GeneralRe: Starting Pocket Outlook Pin
localhost808013-Jun-08 12:48
localhost808013-Jun-08 12:48 
Questionhow about receiving an SMS? Pin
sandred198221-Dec-04 23:35
sandred198221-Dec-04 23:35 
AnswerRe: how about receiving an SMS? Pin
EK_Kiwi5-Jan-05 3:08
EK_Kiwi5-Jan-05 3:08 
AnswerRe: how about receiving an SMS? Pin
EK_Kiwi5-Jan-05 3:20
EK_Kiwi5-Jan-05 3:20 
AnswerRe: how about receiving an SMS? Pin
yzx00236-Jan-05 13:28
yzx00236-Jan-05 13:28 
QuestionRe: how about receiving an SMS? Pin
eantaru26-Apr-07 22:37
eantaru26-Apr-07 22:37 
GeneralQuestion Pin
yzx002320-Dec-04 14:47
yzx002320-Dec-04 14:47 
GeneralRe: Question Pin
EK_Kiwi5-Jan-05 3:04
EK_Kiwi5-Jan-05 3:04 
GeneralUsing IRDA on PPC2003 Pin
jsoftmonopoli4-Nov-04 1:49
jsoftmonopoli4-Nov-04 1:49 
GeneralRe: Using IRDA on PPC2003 Pin
EK_Kiwi10-Nov-04 11:50
EK_Kiwi10-Nov-04 11:50 
GeneralStrange link errors Pin
Alex Evans2-Oct-04 22:05
Alex Evans2-Oct-04 22:05 
GeneralRe: Strange link errors Pin
EK_Kiwi3-Oct-04 6:42
EK_Kiwi3-Oct-04 6:42 
GeneralRe: Strange link errors Pin
Alex Evans3-Oct-04 16:09
Alex Evans3-Oct-04 16:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.