CString to char* :(

Started by
11 comments, last by crazy_andy 18 years, 10 months ago
Quote:Original post by crazy_andy
neither work :(

there must be a way to do this.

A CEdit box returns a CString, and the inet_addr needs a char *

Is there any other function to replace either of these, to either start with a char[] or use a cstring?


tbh, i don't understand why you're having problems - CString::GetBuffer get buffer will explicitely return an LPCTSTR, so this should be ok as long as UNICODE isn't defined in your project. (like apoch said)

As an alternative to using CString, and at the same time writing unicode/mbcs compliant code to be safe, you could write something like:

TCHAR szHostname[ MAX_BUFFER + 1 ];
m_edtUrl.GetWindowText( szHostname, MAX_BUFFER );
const char* pcHostname( T2CA( szHostname ) );

if ( inet_addr( pcHostname ) == INADDR_NONE )

Assuming that your edit box is called m_edtUrl. i've not tested this, and you might need to include atlconv.h in your pch - but it should explicitely get you a char* in all cases.
Advertisement
Quote:Original post by crazy_andy
neither work :(

there must be a way to do this.

A CEdit box returns a CString, and the inet_addr needs a char *

Is there any other function to replace either of these, to either start with a char[] or use a cstring?




Post the exact code you're trying to use and any/all compiler or linker warnings. I have a feeling it's just a simple miscommunication somewhere. I do know for a fact the solutions that have been posted will do exactly what you need to do, but sometimes going from an answer to an implemented solution can be tricky.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

OK, the AP said AS LONG AS UNICODE IS NOT DEFINED, which was the problem. I changed it, and it works great now. Now I need to read that tutorial that Drew_Benton posted, which I will do as soon as I get some free time. Thanks alot everyone for all your help.
www.stickskate.com -> check it out, some gnarly stick skating movies

This topic is closed to new replies.

Advertisement