为什么自己写的smartphone发送短信程序,发送中文会是乱码?该怎么解决
为什么自己写的smartphone发送短信程序,发送中文会是乱码?
代码如下:
ICEMAPISession * mapiSession = NULL;
IMAPITable * msgTable = NULL;
IMsgStore * msgStore = NULL;
LPMAPITABLE pTable = NULL;
SRowSet * pRows = NULL;
HRESULT hr;
if (MAPILogonEx(0,NULL,NULL,0,(LPMAPISESSION *)&mapiSession) != S_OK)
{
MessageBox(_T( "Failed to logon "),_T( "Error "));
}
else
{
SizedSPropTagArray(2, PropTagArr) = {2,{PR_DISPLAY_NAME,PR_ENTRYID}};
hr = mapiSession-> GetMsgStoresTable(MAPI_UNICODE,&msgTable);
hr = msgTable-> SetColumns((LPSPropTagArray)&PropTagArr, 0);
if (!hr)
{
do
{
hr = msgTable-> QueryRows(1,0,&pRows);
LPSPropValue lpProp;
lpProp = &pRows-> aRow[0].lpProps[0];
if(_tcscmp( lpProp-> Value.LPSZ, _T( "SMS ") ) == 0 )
{
break;
}
FreeProws(pRows);
pRows = NULL;
}while (!hr);
}
hr = mapiSession-> OpenMsgStore(0,
pRows-> aRow[0].lpProps[1].Value.bin.cb,
(ENTRYID*)pRows-> aRow[0].lpProps[1].Value.bin.lpb,
NULL, MDB_NO_DIALOG | MAPI_BEST_ACCESS,
&msgStore);
//////////////////////////////////////////////////////////////
IMAPIFolder* pFolder;
LPSPropValue rgprops = NULL;
SizedSPropTagArray(1, rgTags) = { 1, {PR_CE_IPM_DRAFTS_ENTRYID} }; //PR_CE_IPM_DRAFTS_ENTRYID PR_CE_IPM_INBOX_ENTRYID
ULONG ulValues = 0;
int nMsg=0;
msgStore-> GetProps((LPSPropTagArray)&rgTags, MAPI_UNICODE, &ulValues, &rgprops);
hr=msgStore-> OpenEntry(rgprops[0].Value.bin.cb, (LPENTRYID)rgprops[0].Value.bin.lpb, NULL, MAPI_MODIFY, NULL, (LPUNKNOWN*)&pFolder );
LPMESSAGE lpMsg=NULL;
SPropValue Data[3];
TCHAR szNum[12];
char szBody[80];
TCHAR* pszSubjectW = NULL;
hr=pFolder-> CreateMessage(NULL,0,&lpMsg);
swprintf(szNum,_T( "13560185253 "));
sprintf(szBody, "Why not?~ ");
pszSubjectW = ToUTF8(szBody);
Data[0].ulPropTag = PR_SUBJECT;
Data[0].Value.lpszW =pszSubjectW;//
Data[1].ulPropTag = PR_MSG_STATUS;
Data[1].Value.ul = MSGSTATUS_RECTYPE_SMS;//_T( "13286873736 ");
Data[2].ulPropTag = PR_MESSAGE_FLAGS;
Data[2].Value.ul = MSGFLAG_UNSENT|MSGFLAG_FROMME;
hr=lpMsg-> SetProps(sizeof(Data)/sizeof(Data[0]),(LPSPropValue)Data,NULL);
///
ADRLIST adrList;
SPropValue val[3];
ZeroMemory(&val, sizeof(val));
adrList.cEntries = 1;
代码如下:
ICEMAPISession * mapiSession = NULL;
IMAPITable * msgTable = NULL;
IMsgStore * msgStore = NULL;
LPMAPITABLE pTable = NULL;
SRowSet * pRows = NULL;
HRESULT hr;
if (MAPILogonEx(0,NULL,NULL,0,(LPMAPISESSION *)&mapiSession) != S_OK)
{
MessageBox(_T( "Failed to logon "),_T( "Error "));
}
else
{
SizedSPropTagArray(2, PropTagArr) = {2,{PR_DISPLAY_NAME,PR_ENTRYID}};
hr = mapiSession-> GetMsgStoresTable(MAPI_UNICODE,&msgTable);
hr = msgTable-> SetColumns((LPSPropTagArray)&PropTagArr, 0);
if (!hr)
{
do
{
hr = msgTable-> QueryRows(1,0,&pRows);
LPSPropValue lpProp;
lpProp = &pRows-> aRow[0].lpProps[0];
if(_tcscmp( lpProp-> Value.LPSZ, _T( "SMS ") ) == 0 )
{
break;
}
FreeProws(pRows);
pRows = NULL;
}while (!hr);
}
hr = mapiSession-> OpenMsgStore(0,
pRows-> aRow[0].lpProps[1].Value.bin.cb,
(ENTRYID*)pRows-> aRow[0].lpProps[1].Value.bin.lpb,
NULL, MDB_NO_DIALOG | MAPI_BEST_ACCESS,
&msgStore);
//////////////////////////////////////////////////////////////
IMAPIFolder* pFolder;
LPSPropValue rgprops = NULL;
SizedSPropTagArray(1, rgTags) = { 1, {PR_CE_IPM_DRAFTS_ENTRYID} }; //PR_CE_IPM_DRAFTS_ENTRYID PR_CE_IPM_INBOX_ENTRYID
ULONG ulValues = 0;
int nMsg=0;
msgStore-> GetProps((LPSPropTagArray)&rgTags, MAPI_UNICODE, &ulValues, &rgprops);
hr=msgStore-> OpenEntry(rgprops[0].Value.bin.cb, (LPENTRYID)rgprops[0].Value.bin.lpb, NULL, MAPI_MODIFY, NULL, (LPUNKNOWN*)&pFolder );
LPMESSAGE lpMsg=NULL;
SPropValue Data[3];
TCHAR szNum[12];
char szBody[80];
TCHAR* pszSubjectW = NULL;
hr=pFolder-> CreateMessage(NULL,0,&lpMsg);
swprintf(szNum,_T( "13560185253 "));
sprintf(szBody, "Why not?~ ");
pszSubjectW = ToUTF8(szBody);
Data[0].ulPropTag = PR_SUBJECT;
Data[0].Value.lpszW =pszSubjectW;//
Data[1].ulPropTag = PR_MSG_STATUS;
Data[1].Value.ul = MSGSTATUS_RECTYPE_SMS;//_T( "13286873736 ");
Data[2].ulPropTag = PR_MESSAGE_FLAGS;
Data[2].Value.ul = MSGFLAG_UNSENT|MSGFLAG_FROMME;
hr=lpMsg-> SetProps(sizeof(Data)/sizeof(Data[0]),(LPSPropValue)Data,NULL);
///
ADRLIST adrList;
SPropValue val[3];
ZeroMemory(&val, sizeof(val));
adrList.cEntries = 1;