CString cast to LPCTSTR cast error 
Author Message
 CString cast to LPCTSTR cast error

void CDlg::OnClientconnect() {
    CString m_strIPEdit;
    unsigned long ip;
    ip = inet_addr((LPCTSTR)m_strIPEdit);

Quote:
}

Dlg.cpp(72) : error C2664: 'inet_addr' : cannot convert parameter 1 from
'const unsigned short *' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast,
C-style cast or function-style cast


Fri, 09 Jul 2004 17:09:04 GMT  
 CString cast to LPCTSTR cast error
I see that you work with embedded device so it's windows CE.
The CString there is class contain unicode string , but
socket functions ( as  Berkeley prototype ) use chars.
So you need translate CString data( unicode string ) to array of chars and
only after that use the inet_addr()
My advise , send such questions only to embedded , because from desktop vc
point of view it looks OK , but
opposite in Windows CE.

HTH
Arkady


Quote:
> void CDlg::OnClientconnect() {
>     CString m_strIPEdit;
>     unsigned long ip;
>     ip = inet_addr((LPCTSTR)m_strIPEdit);
> }

> Dlg.cpp(72) : error C2664: 'inet_addr' : cannot convert parameter 1 from
> 'const unsigned short *' to 'const char *'
> Types pointed to are unrelated; conversion requires reinterpret_cast,
> C-style cast or function-style cast



Fri, 09 Jul 2004 17:34:34 GMT  
 CString cast to LPCTSTR cast error
That's right.

To get around this, use the W2A macro to convert the Unicode string to
Ascii, then use the resulting string and pass *that* to your sockets
call.  You'll also have to use the USES_CONVERSION macro.  These
macros are in various places, including #include <AfxPriv.h>.  Look in
your MSDN, perhaps.  I don't have the exact macro invocation sequence
in front of me.

HTH.

Michael

Quote:

> I see that you work with embedded device so it's windows CE.
> The CString there is class contain unicode string , but
> socket functions ( as  Berkeley prototype ) use chars.
> So you need translate CString data( unicode string ) to array of chars and
> only after that use the inet_addr()
> My advise , send such questions only to embedded , because from desktop vc
> point of view it looks OK , but
> opposite in Windows CE.

> HTH
> Arkady



> > void CDlg::OnClientconnect() {
> >     CString m_strIPEdit;
> >     unsigned long ip;
> >     ip = inet_addr((LPCTSTR)m_strIPEdit);
> > }

> > Dlg.cpp(72) : error C2664: 'inet_addr' : cannot convert parameter 1 from
> > 'const unsigned short *' to 'const char *'
> > Types pointed to are unrelated; conversion requires reinterpret_cast,
> > C-style cast or function-style cast



Fri, 09 Jul 2004 22:17:39 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CString cast to LPCTSTR cast error

2. CString cast to LPCTSTR cast error

3. Casting CString -> LPCTSTR

4. Using CString functionality without CString variable/cast operator

5. Using CString functionality without CString variable/cast operator

6. How to cast CString* to CString

7. (LPCTSTR)(LPTSTR) type casting.

8. old style casts vs new style casts

9. casting of struct element void pointer casting

10. Cast...always cast...

11. malloc: to cast or not to cast

12. to cast or not to cast?

 

 
Powered by phpBB® Forum Software