From: Julian Smart Date: Thu, 3 Apr 2003 10:42:56 +0000 (+0000) Subject: Applied patch [ 708377 ] Make NET (smapi.cpp) UNICODE compatible X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5a618a14c627c87a2ea642bd8395b74d72e614ba?hp=333a6456b96c38d0d7d1976d94bb2cc255850da1 Applied patch [ 708377 ] Make NET (smapi.cpp) UNICODE compatible git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19961 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/contrib/src/net/smapi.cpp b/contrib/src/net/smapi.cpp index b684d08e2b..43421b8ebd 100644 --- a/contrib/src/net/smapi.cpp +++ b/contrib/src/net/smapi.cpp @@ -145,12 +145,20 @@ bool wxMapiSession::Logon(const wxString& sProfileName, const wxString& sPasswor LPSTR pszProfileName = NULL; LPSTR pszPassword = NULL; + wxCharBuffer cbProfile(1),cbPassword(1); if (nProfileLength) { // pszProfileName = T2A((LPTSTR) (LPCTSTR) sProfileName); // pszPassword = T2A((LPTSTR) (LPCTSTR) sPassword); +#ifndef UNICODE pszProfileName = (LPSTR) sProfileName.c_str(); pszPassword = (LPSTR) sPassword.c_str(); +#else + cbProfile = sProfileName.mb_str(); + cbPassword = sPassword.mb_str(); + pszProfileName = cbProfile.data(); + pszPassword = cbPassword.data(); +#endif } //Setup the flags & UIParam parameters used in the MapiLogon call @@ -252,7 +260,13 @@ bool wxMapiSession::Resolve(const wxString& sName, void* lppRecip1) //Call the MAPIResolveName function // LPSTR lpszAsciiName = T2A((LPTSTR) (LPCTSTR) sName); +#ifndef UNICODE LPSTR lpszAsciiName = (LPSTR) sName.c_str(); +#else + wxCharBuffer cbName(1); + cbName = sName.mb_str(); + LPSTR lpszAsciiName = cbName.data(); +#endif ULONG nError = m_data->m_lpfnMAPIResolveName(m_data->m_hSession, 0, lpszAsciiName, 0, 0, lppRecip); if (nError != SUCCESS_SUCCESS) { @@ -277,8 +291,16 @@ bool wxMapiSession::Send(wxMailMessage& message) //Create the MapiMessage structure to match the message parameter send into us MapiMessage mapiMessage; ZeroMemory(&mapiMessage, sizeof(mapiMessage)); +#ifndef UNICODE mapiMessage.lpszSubject = (LPSTR) message.m_subject.c_str(); mapiMessage.lpszNoteText = (LPSTR) message.m_body.c_str(); +#else + wxCharBuffer cbSubject(1),cbBody(1),cbOriginator(1); + cbSubject = message.m_subject.mb_str(); + cbBody = message.m_body.mb_str(); + mapiMessage.lpszSubject = cbSubject.data(); + mapiMessage.lpszNoteText = cbBody.data(); +#endif // mapiMessage.lpszSubject = T2A((LPTSTR) (LPCTSTR) message.m_subject); // mapiMessage.lpszNoteText = T2A((LPTSTR) (LPCTSTR) message.m_body); mapiMessage.nRecipCount = message.m_to.GetCount() + message.m_cc.GetCount() + message.m_bcc.GetCount(); @@ -295,7 +317,12 @@ bool wxMapiSession::Send(wxMailMessage& message) mapiMessage.lpOriginator->ulRecipClass = MAPI_ORIG; // TODO Do we have to call Resolve? +#ifndef UNICODE mapiMessage.lpOriginator->lpszName = (LPSTR) message.m_from.c_str(); +#else + cbOriginator = message.m_from.mb_str(); + mapiMessage.lpOriginator->lpszName = cbOriginator.data(); +#endif } //Setup the "To" recipients @@ -314,13 +341,17 @@ bool wxMapiSession::Send(wxMailMessage& message) if (Resolve(sName, (void*) &lpTempRecip)) { //Resolve worked, put the resolved name back into the sName - sName = lpTempRecip->lpszName; + sName = wxString(lpTempRecip->lpszName,wxConvCurrent); //Don't forget to free up the memory MAPI allocated for us m_data->m_lpfnMAPIFreeBuffer(lpTempRecip); } //recip.lpszName = T2A((LPTSTR) (LPCTSTR) sName); +#ifndef UNICODE recip.lpszName = (LPSTR) sName.c_str(); +#else + recip.lpszName = sName.mb_str().release(); +#endif ++nRecipIndex; } @@ -339,13 +370,17 @@ bool wxMapiSession::Send(wxMailMessage& message) if (Resolve(sName, (void*) &lpTempRecip)) { //Resolve worked, put the resolved name back into the sName - sName = lpTempRecip->lpszName; + sName = wxString(lpTempRecip->lpszName,wxConvCurrent); //Don't forget to free up the memory MAPI allocated for us m_data->m_lpfnMAPIFreeBuffer(lpTempRecip); } //recip.lpszName = T2A((LPTSTR) (LPCTSTR) sName); +#ifndef UNICODE recip.lpszName = (LPSTR) sName.c_str(); +#else + recip.lpszName = sName.mb_str().release(); +#endif ++nRecipIndex; } @@ -364,13 +399,17 @@ bool wxMapiSession::Send(wxMailMessage& message) if (Resolve(sName, (void*) &lpTempRecip)) { //Resolve worked, put the resolved name back into the sName - sName = lpTempRecip->lpszName; + sName = wxString(lpTempRecip->lpszName,wxConvCurrent); //Don't forget to free up the memory MAPI allocated for us m_data->m_lpfnMAPIFreeBuffer(lpTempRecip); } //recip.lpszName = T2A((LPTSTR) (LPCTSTR) sName); +#ifndef UNICODE recip.lpszName = (LPSTR) sName.c_str(); +#else + recip.lpszName = sName.mb_str().release(); +#endif ++nRecipIndex; } @@ -395,7 +434,11 @@ bool wxMapiSession::Send(wxMailMessage& message) wxString& sFilename = message.m_attachments[i]; //file.lpszPathName = T2A((LPTSTR) (LPCTSTR) sFilename); +#ifndef UNICODE file.lpszPathName = (LPSTR) sFilename.c_str(); +#else + file.lpszPathName = sFilename.mb_str().release(); +#endif //file.lpszFileName = file.lpszPathName; file.lpszFileName = NULL; @@ -403,7 +446,11 @@ bool wxMapiSession::Send(wxMailMessage& message) { wxString& sTitle = message.m_attachmentTitles[i]; //file.lpszFileName = T2A((LPTSTR) (LPCTSTR) sTitle); +#ifndef UNICODE file.lpszFileName = (LPSTR) sTitle.c_str(); +#else + file.lpszFileName = sTitle.mb_str().release(); +#endif } } } @@ -423,10 +470,24 @@ bool wxMapiSession::Send(wxMailMessage& message) //Tidy up the Attachements if (nAttachmentSize) + { +#ifdef UNICODE + for (int i = 0;i < nAttachmentSize;i++) + { + free(mapiMessage.lpFiles[i].lpszPathName); + free(mapiMessage.lpFiles[i].lpszFileName); + } +#endif delete [] mapiMessage.lpFiles; + } //Free up the Recipients and Originator memory +#ifdef UNICODE + for (int i = 0;i < nRecipIndex;i++) + free(mapiMessage.lpRecips[i].lpszName); +#endif delete [] mapiMessage.lpRecips; + delete mapiMessage.lpOriginator; return bSuccess; @@ -436,4 +497,3 @@ long wxMapiSession::GetLastError() const { return m_data->m_nLastError; } -