Re: Conversion from ANSI to UNICODE errors

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Relvinian (m_at_msn.com)
Date: 07/14/04


Date: Tue, 13 Jul 2004 22:46:04 -0600

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" <alegr@earthlink.net> wrote in message
news:e3VQPrVaEHA.4052@TK2MSFTNGP10.phx.gbl...
> Don't do those casts. You're just masking the error.
>
> "Relvinian" <m@msn.com> wrote in message
> news:zLGdnYPtEKJOKWndRVn-sQ@comcast.com...
> > 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" <fuzzlog2000@earthlink.net> wrote in message
> > news:zwVIc.2044$Qu5.1548@newsread2.news.pas.earthlink.net...
> > > 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
> > >
> > >
> >
> >
>
>



Relevant Pages

  • Re: C compilation problem
    ... which doesnt compile and gives me incompatible pointer type ... Actually since my pointer can hold 16 bits, i want to extract lower 8 ... The error message you get is unusual so it might help is you the actual ... it's really important to find out why your compiler objects to ...
    (comp.lang.c)
  • Re: Amusing C, amusing compiler
    ... the visual studio 2005, also give an run-time error message, said ptr ... It's undefined behaviour to add one to an uninitialised pointer, since it does not point at any object. ... VS 2005 is being helpful in diagnosing this undefined behaviour for you, though it is not required to do so. ... compiler, and return 1 directly. ...
    (comp.lang.c)
  • Re: method printing values from a vector not working
    ... a pointer, ... I can't make anything with that error message. ... First fix your first problem ... are located in the same function and the compiler might just got confused with your ...
    (comp.lang.cpp)
  • Re: Question about Tcl_GetDouble and floats
    ... 'double*' means 'pointer to double', ... I tried that...I still get the same error message. ... (It is always surprising that in a language where counting starts at ... the compiler counts from 1 ...) ...
    (comp.lang.tcl)
  • Re: How to convert Infix notation to postfix notation
    ... and make all strings const save where the intent ... function whose contract is to change the string. ... the compiler "just" prevents the string ... try to do using the pointer you get. ...
    (comp.lang.c)