Discussion:
Conversion from ANSI to UNICODE errors
(too old to reply)
Fausto Lopez
2004-07-13 18:06:23 UTC
Permalink
Can any body help to figure out why the following code generates the
following errors at compile time, and also any suggestions on how to fix it?

BACKGROUND INFO
--HRESULT AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW) <-- Function
definition
--private:
CString m_saveAsFilename; <-- Private variable definition inside class
--CString fullpath = GetDocument()->GetPathName();

CODE IN QUESTION
-- AnsiToUnicode(m_saveAsFilename,&m_pwBuffer);
-- AnsiToUnicode(fullpath,&m_pwBuffer);

ERROR MESSAGED FOR BOTH FUNCTION CALLS
error C2664: 'AnsiToUnicode' : cannot convert parameter 1 from 'class
CString' to 'const char *'
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called


Fausto
Jonathan Wood
2004-07-13 18:27:27 UTC
Permalink
Are you compiling with _UNICODE defined?

If so, CString will contain Unicode strings and will only be able to
automatically convert to w_char*.
--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm
Post by Fausto Lopez
Can any body help to figure out why the following code generates the
following errors at compile time, and also any suggestions on how to fix it?
BACKGROUND INFO
--HRESULT AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW) <-- Function
definition
CString m_saveAsFilename; <-- Private variable definition inside class
--CString fullpath = GetDocument()->GetPathName();
CODE IN QUESTION
-- AnsiToUnicode(m_saveAsFilename,&m_pwBuffer);
-- AnsiToUnicode(fullpath,&m_pwBuffer);
ERROR MESSAGED FOR BOTH FUNCTION CALLS
error C2664: 'AnsiToUnicode' : cannot convert parameter 1 from 'class
CString' to 'const char *'
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called
Fausto
Relvinian
2004-07-14 04:22:10 UTC
Permalink
Fausto,

What this error message is saying is that the compiler can't convert a
CString object to a const char*. You will need to double type-cast the
CString object to get it into a const char* format.

Example:

(LPCSTR)(LPCTSTR)m_saveAsFilename
(LPCSTR)(LPCTSTR)fullpath

Also note:
If you are compiling the project with _UNICODE defined, CString
automatically uses unicode as the default (could be why you are receiving
this compiler error message). This could cause problems with your
type-casting if you have it so. If you don't have _UNICODE defined, the
double type-cast should work ok for you.

Relvinian
Post by Fausto Lopez
Can any body help to figure out why the following code generates the
following errors at compile time, and also any suggestions on how to fix it?
BACKGROUND INFO
--HRESULT AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW) <-- Function
definition
CString m_saveAsFilename; <-- Private variable definition inside class
--CString fullpath = GetDocument()->GetPathName();
CODE IN QUESTION
-- AnsiToUnicode(m_saveAsFilename,&m_pwBuffer);
-- AnsiToUnicode(fullpath,&m_pwBuffer);
ERROR MESSAGED FOR BOTH FUNCTION CALLS
error C2664: 'AnsiToUnicode' : cannot convert parameter 1 from 'class
CString' to 'const char *'
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called
Fausto
Alexander Grigoriev
2004-07-14 04:27:02 UTC
Permalink
Don't do those casts. You're just masking the error.
Post by Relvinian
Fausto,
What this error message is saying is that the compiler can't convert a
CString object to a const char*. You will need to double type-cast the
CString object to get it into a const char* format.
(LPCSTR)(LPCTSTR)m_saveAsFilename
(LPCSTR)(LPCTSTR)fullpath
If you are compiling the project with _UNICODE defined, CString
automatically uses unicode as the default (could be why you are receiving
this compiler error message). This could cause problems with your
type-casting if you have it so. If you don't have _UNICODE defined, the
double type-cast should work ok for you.
Relvinian
Post by Fausto Lopez
Can any body help to figure out why the following code generates the
following errors at compile time, and also any suggestions on how to fix
it?
Post by Fausto Lopez
BACKGROUND INFO
--HRESULT AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW) <-- Function
definition
CString m_saveAsFilename; <-- Private variable definition inside
class
Post by Fausto Lopez
--CString fullpath = GetDocument()->GetPathName();
CODE IN QUESTION
-- AnsiToUnicode(m_saveAsFilename,&m_pwBuffer);
-- AnsiToUnicode(fullpath,&m_pwBuffer);
ERROR MESSAGED FOR BOTH FUNCTION CALLS
error C2664: 'AnsiToUnicode' : cannot convert parameter 1 from 'class
CString' to 'const char *'
No user-defined-conversion operator available that can perform
this
Post by Fausto Lopez
conversion, or the operator cannot be called
Fausto
Relvinian
2004-07-14 04:46:04 UTC
Permalink
I wouldn't necessarily do them --- besides, if you watch the "guts", meaning
looking at the assembly, a pointer is a pointer, doesn't matter what type it
is. Just a four-byte value!

But if you know what the data is and are always aware, you'll be ok. Of
course, the better solution is finding out why!

But if you *always* compile for ANSI systems and you are using a CString
object and trying to pass data to a const char*, type casting is just fine.
But the question remains, why are you using CString or trying to pass data
to a const char* function instead of a (possible) w_char* function?

Relvinian
Post by Alexander Grigoriev
Don't do those casts. You're just masking the error.
Post by Relvinian
Fausto,
What this error message is saying is that the compiler can't convert a
CString object to a const char*. You will need to double type-cast the
CString object to get it into a const char* format.
(LPCSTR)(LPCTSTR)m_saveAsFilename
(LPCSTR)(LPCTSTR)fullpath
If you are compiling the project with _UNICODE defined, CString
automatically uses unicode as the default (could be why you are receiving
this compiler error message). This could cause problems with your
type-casting if you have it so. If you don't have _UNICODE defined, the
double type-cast should work ok for you.
Relvinian
Post by Fausto Lopez
Can any body help to figure out why the following code generates the
following errors at compile time, and also any suggestions on how to fix
it?
Post by Fausto Lopez
BACKGROUND INFO
--HRESULT AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW) <-- Function
definition
CString m_saveAsFilename; <-- Private variable definition inside
class
Post by Fausto Lopez
--CString fullpath = GetDocument()->GetPathName();
CODE IN QUESTION
-- AnsiToUnicode(m_saveAsFilename,&m_pwBuffer);
-- AnsiToUnicode(fullpath,&m_pwBuffer);
ERROR MESSAGED FOR BOTH FUNCTION CALLS
error C2664: 'AnsiToUnicode' : cannot convert parameter 1 from 'class
CString' to 'const char *'
No user-defined-conversion operator available that can perform
this
Post by Fausto Lopez
conversion, or the operator cannot be called
Fausto
Alexander Grigoriev
2004-07-14 13:45:50 UTC
Permalink
You don't need a cast to get LPCTSTR from CString (other than when passing
it to a printf/Format).
Post by Relvinian
I wouldn't necessarily do them --- besides, if you watch the "guts", meaning
looking at the assembly, a pointer is a pointer, doesn't matter what type it
is. Just a four-byte value!
But if you know what the data is and are always aware, you'll be ok. Of
course, the better solution is finding out why!
But if you *always* compile for ANSI systems and you are using a CString
object and trying to pass data to a const char*, type casting is just fine.
But the question remains, why are you using CString or trying to pass data
to a const char* function instead of a (possible) w_char* function?
Relvinian
Post by Alexander Grigoriev
Don't do those casts. You're just masking the error.
Post by Relvinian
Fausto,
What this error message is saying is that the compiler can't convert a
CString object to a const char*. You will need to double type-cast the
CString object to get it into a const char* format.
(LPCSTR)(LPCTSTR)m_saveAsFilename
(LPCSTR)(LPCTSTR)fullpath
If you are compiling the project with _UNICODE defined, CString
automatically uses unicode as the default (could be why you are
receiving
Post by Alexander Grigoriev
Post by Relvinian
this compiler error message). This could cause problems with your
type-casting if you have it so. If you don't have _UNICODE defined, the
double type-cast should work ok for you.
Relvinian
Post by Fausto Lopez
Can any body help to figure out why the following code generates the
following errors at compile time, and also any suggestions on how to
fix
Post by Alexander Grigoriev
Post by Relvinian
it?
Post by Fausto Lopez
BACKGROUND INFO
--HRESULT AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW) <-- Function
definition
CString m_saveAsFilename; <-- Private variable definition inside
class
Post by Fausto Lopez
--CString fullpath = GetDocument()->GetPathName();
CODE IN QUESTION
-- AnsiToUnicode(m_saveAsFilename,&m_pwBuffer);
-- AnsiToUnicode(fullpath,&m_pwBuffer);
ERROR MESSAGED FOR BOTH FUNCTION CALLS
error C2664: 'AnsiToUnicode' : cannot convert parameter 1 from 'class
CString' to 'const char *'
No user-defined-conversion operator available that can perform
this
Post by Fausto Lopez
conversion, or the operator cannot be called
Fausto
GuitarBill
2004-07-14 05:17:21 UTC
Permalink
That could be quite a useful debugging tool - if [when] your program crashes
you could just look for these: (LPCSTR)(LPCTSTR) and immediately find where
the problem is.

Bill
Post by Relvinian
Fausto,
What this error message is saying is that the compiler can't convert a
CString object to a const char*. You will need to double type-cast the
CString object to get it into a const char* format.
(LPCSTR)(LPCTSTR)m_saveAsFilename
(LPCSTR)(LPCTSTR)fullpath
If you are compiling the project with _UNICODE defined, CString
automatically uses unicode as the default (could be why you are receiving
this compiler error message). This could cause problems with your
type-casting if you have it so. If you don't have _UNICODE defined, the
double type-cast should work ok for you.
Relvinian
Post by Fausto Lopez
Can any body help to figure out why the following code generates the
following errors at compile time, and also any suggestions on how to fix
it?
Post by Fausto Lopez
BACKGROUND INFO
--HRESULT AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW) <-- Function
definition
CString m_saveAsFilename; <-- Private variable definition inside
class
Post by Fausto Lopez
--CString fullpath = GetDocument()->GetPathName();
CODE IN QUESTION
-- AnsiToUnicode(m_saveAsFilename,&m_pwBuffer);
-- AnsiToUnicode(fullpath,&m_pwBuffer);
ERROR MESSAGED FOR BOTH FUNCTION CALLS
error C2664: 'AnsiToUnicode' : cannot convert parameter 1 from 'class
CString' to 'const char *'
No user-defined-conversion operator available that can perform
this
Post by Fausto Lopez
conversion, or the operator cannot be called
Fausto
Mihai N.
2004-07-14 10:10:24 UTC
Permalink
Post by Fausto Lopez
--CString fullpath = GetDocument()->GetPathName();
-- AnsiToUnicode(fullpath,&m_pwBuffer);
You try to use the CString as a target for the function.
This does not work.
You should get a buffer big enough (GetBuffer or GetBufferSetLength)
use this as a parameter to your call, then release it
(ReleaseBuffer or ReleaseBufferSetLength)

And you should be carefull that the CString is ANSI.
And with Dev.Studio 6 or older the only way to do this is
to have a non-unicode application.
--
Mihai
-------------------------
Replace _year_ with _ to get the real email
s***@gmail.com
2018-04-06 08:09:56 UTC
Permalink
Upgrade Outlook PST software quickly performs ANSI PST to UNICODE PST and UNICODE PST to ANSI PST. The Software is enhanced with an advanced conversion algorithm that support batch operations to convert PST files. It can safely convert PST files without causing any alteration to the original files and folders. The software supports all higher or lower versions of Microsoft Outlook email client application.
visit here:- http://www.mergeoutlookpst.com/upgrade-outlook-pst
s***@gmail.com
2018-04-06 08:10:38 UTC
Permalink
Upgrade Outlook PST software quickly performs ANSI PST to UNICODE PST and UNICODE PST to ANSI PST. The Software is enhanced with an advanced conversion algorithm that support batch operations to convert PST files. It can safely convert PST files without causing any alteration to the original files and folders. The software supports all higher or lower versions of Microsoft Outlook email client application.
visit here:- http://www.mergeoutlookpst.com/upgrade-outlook-pst
t***@gmail.com
2020-02-10 12:01:20 UTC
Permalink
You can easily convert ANSI PST Files to Unicode PST Files format as well as your contacts and Calendar info With advanced PST Upgrade Software. Microsoft Outlook 2002 and earlier versions support ANSI file format that has a size limitation of 2 GB. On the other hand, Microsoft Outlook 2003 and later versions support Unicode file format that has a size limitation of 20 GB to 50 GB. If you're looking for a way to upgrade the PST file from ANSI format to Unicode format, The software enhanced with an advanced conversion algorithm that supports batch operations to convert PST files. For more details click here: https://www.osttopstapp.com/ansi-to-unicode-pst.html
Jenny Carner
2022-07-09 06:24:35 UTC
Permalink
ANSI to Unicode PST is now possible with PST Upgrade Program. It's a suitable solution to convert ANSI PST data file to Unicode PST file format. PST Upgrade Program allows you to easily read large or maximum size of Outlook PST file and process them to explore the ANSI or UNICODE PST files. You can select ANSI PST file and quickly upgrade into UNICODE PST file without any data loss that could be easily open in all versions of Outlook. This application supports all MS Outlook and Windows OS versions.

Visit here:- https://www.sysessential.com/pst-upgrade/

Continue reading on narkive:
Loading...