1 Attachment(s)
Need Help Or Hints with _UNICODE conversion
I am in the process of compiling in _UNICODE in order to display multi-languages in my program.
When I first started this, I had about 500 compile errors (mostly needed _T() and put in some TCHAR for char).
I am down to about the last 20 (pant...pant...) and this attached IMapi.cpp file is one of the problems I can't quite figure out. I use this for sending email through MAPI and it has some functions with LPCTSTR and LPTSTR params that don't work.
Was wondering if some one could browse the attached .cpp and .h and give me some clues on fixing these errors for _UNICODE compile.
thanks
IMapi.cpp
c:\projects\imapi.h(28) : error C2440: '=' : cannot convert from 'unsigned short *' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.h(33) : error C2440: '=' : cannot convert from 'unsigned short *' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.cpp(92) : error C2440: '=' : cannot convert from 'unsigned short *' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.cpp(93) : error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.cpp(108) : error C2440: '=' : cannot convert from 'unsigned short *' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.cpp(109) : error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.cpp(133) : error C2440: '=' : cannot convert from 'unsigned short *' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.cpp(134) : error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.cpp(138) : error C2440: '=' : cannot convert from 'unsigned short *' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.cpp(139) : error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.cpp(158) : error C2440: '=' : cannot convert from 'unsigned short *' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.h(28) : error C2440: '=' : cannot convert from 'unsigned short *' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\projects\imapi.h(33) : error C2440: '=' : cannot convert from 'unsigned short *' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Re: Need Help Or Hints with _UNICODE conversion
your m_message.lpszSubject is a char*, and the subject is a TCHAR* which under unicode build becomes a wchar* - so thats yoru first error.
use WideCharToMultiByte to convert subject to a char*
once you get this working, you will solve all your other errors in a minute -
hth.
Re: Need Help Or Hints with _UNICODE conversion
so......................
This is what i have:
Code:
CIMapi mail;
mail.To( lpszTO ); // Set recipient name
// mail.To("[email protected]"); // Second recipient
// mail.Cc(lpszCC); // CC recipient
mail.Subject(lpszSubject); // Subject of this email
mail.Text(lpszMessage); // Set body text
And I need to add WideCharToMultiByte() before mail.Subject() and substitute new value?
..
Re: Need Help Or Hints with _UNICODE conversion
Did this:
Code:
LPSTR lpMultiByteStr;
WideCharToMultiByte(CP_ACP,0,LPCWSTR(lpszSubject),-1, lpMultiByteStr,1024, NULL, NULL);
mail.Subject(lpMultiByteStr); // Subject of this email
and got this:
error C2664: 'Subject' : cannot convert parameter 1 from 'char *' to 'const unsigned short *'
Subject declaration:
Code:
void Subject(LPCTSTR subject) { m_message.lpszSubject = (LPTSTR) subject; }
thought you said i needed char * ??
.
Re: Need Help Or Hints with _UNICODE conversion
I was talking about your first error message, it happens in the ctor in your header file at line 28.
c:\projects\imapi.h(28) : error C2440: '=' : cannot convert from 'unsigned short *' to 'char *'
Re: Need Help Or Hints with _UNICODE conversion
Yea,,,, the code line above your message is line 28, the Subject() method (ctor).
?
The mail.Subject(lpMultiByteStr); calls the line 28.
So I converted the Subject param to a char* using widechartomultibyte() and its now saying it needs to be an unsigned short * instead?
Here is the m_message structure:
Code:
typedef struct
{
ULONG ulReserved; /* Reserved for future use (M.B. 0) */
LPSTR lpszSubject; /* Message Subject */
LPSTR lpszNoteText; /* Message Text */
LPSTR lpszMessageType; /* Message Class */
LPSTR lpszDateReceived; /* in YYYY/MM/DD HH:MM format */
LPSTR lpszConversationID; /* conversation thread ID */
FLAGS flFlags; /* unread,return receipt */
lpMapiRecipDesc lpOriginator; /* Originator descriptor */
ULONG nRecipCount; /* Number of recipients */
lpMapiRecipDesc lpRecips; /* Recipient descriptors */
ULONG nFileCount; /* # of file attachments */
lpMapiFileDesc lpFiles; /* Attachment descriptors */
} MapiMessage, FAR * lpMapiMessage;
Re: Need Help Or Hints with _UNICODE conversion
Boy! you seem to be getting all confused :-)
For a start, here is how you solve the compiile error on line 28. Please note that I am not even thinking about the semantics and/or logical correctness of the code, only looking at your compile error and heres a way to go about solving it.
// Attributes
private:
char m_szSubject[1024];
public:
void Subject(LPCTSTR subject) {
WideCharToMultiByte(CP_ACP,0,subject,-1, m_szSubject,1024, NULL, NULL);
m_message.lpszSubject = m_szSubject;
}
I hope you are getting the hang of it now....
Re: Need Help Or Hints with _UNICODE conversion
Not really confused, just not seeing forrest through the trees.
(or not seeing the logic through the characters).
I did this:
first converted subject to multibyte then before Subject ctor line then....
changed LPCTSTR to char* as here,
void Subject(LPCTSTR subject) { m_message.lpszSubject = (char*) subject; }
This elminated the error , but your way looks better.
I'll try that and see what happens to the other errors.
---------------
somewhat...