Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Conversion from ANSI to UNICODE errors

77 views
Skip to first unread message

Fausto Lopez

unread,
Jul 13, 2004, 2:06:23 PM7/13/04
to
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

unread,
Jul 13, 2004, 2:27:27 PM7/13/04
to
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


"Fausto Lopez" <fuzzl...@earthlink.net> wrote in message
news:zwVIc.2044$Qu5....@newsread2.news.pas.earthlink.net...

Relvinian

unread,
Jul 14, 2004, 12:22:10 AM7/14/04
to
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

"Fausto Lopez" <fuzzl...@earthlink.net> wrote in message
news:zwVIc.2044$Qu5....@newsread2.news.pas.earthlink.net...

Alexander Grigoriev

unread,
Jul 14, 2004, 12:27:02 AM7/14/04
to
Don't do those casts. You're just masking the error.

"Relvinian" <m...@msn.com> wrote in message
news:zLGdnYPtEKJ...@comcast.com...

Relvinian

unread,
Jul 14, 2004, 12:46:04 AM7/14/04
to
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

"Alexander Grigoriev" <al...@earthlink.net> wrote in message
news:e3VQPrVa...@TK2MSFTNGP10.phx.gbl...

GuitarBill

unread,
Jul 14, 2004, 1:17:21 AM7/14/04
to
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

"Relvinian" <m...@msn.com> wrote in message
news:zLGdnYPtEKJ...@comcast.com...

Mihai N.

unread,
Jul 14, 2004, 6:10:24 AM7/14/04
to
> --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

Alexander Grigoriev

unread,
Jul 14, 2004, 9:45:50 AM7/14/04
to
You don't need a cast to get LPCTSTR from CString (other than when passing
it to a printf/Format).

"Relvinian" <m...@msn.com> wrote in message

news:d6GdnYhdBq7...@comcast.com...

simer...@gmail.com

unread,
Apr 6, 2018, 4:09:59 AM4/6/18
to
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
Message has been deleted

thomas...@gmail.com

unread,
Feb 10, 2020, 7:01:23 AM2/10/20
to
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

unread,
Jul 9, 2022, 2:24:38 AM7/9/22
to
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/
0 new messages