CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Nov 2010

    Win32 API multilanguage conversion WCHAR,TCHAR problem?

    I am using recv() func for "GET"ting a web content on port80. And try printing the received content on an Edit Controlon screen, by using ::SendMessage(...WM_SETTEXT...)
    Due to the limitations of pointer types to be compliant to the func presets, I have to make some conversion.
    Everything works fine, with latin letters but I can not anyhow manage to output the foreign language characters properly. Let's say russian.

    How can I do this?Do I need to somehow change the edit control's character set, so as to interpret the passed string buffer as I wish? If so, how?I'll appreciate your help.

    Here I enclose a short abstract from my code (as u might see I enforce UNICODE compilation)
    #define _UNICODE
    #define UNICODE
    #define RECBUFF 100000
    bool KNetCon::WriteToScr(HWND hEditCtl)
       // ----clear screen in edit
    	DWORD writtenBytes;
    	int bytes_sent;
    	int bytes_received=SOCKET_ERROR;
    	char *sendbuf="GET / HTTP/1.0 \r\n\r\n";
    	int i=0;
    	TCHAR* temp=wrecbuf; //*** NOTE: wrecbuf is the main buffer in (this)object.
                                            // and declared in the class interface as ; TCHAR wrecbuf[RECBUFF]
                                                       //***recbuf declared in class interface as: 
                                                       //  char recbuf[RECBUFF] in
    		if(bytes_received==0 || bytes_received==WSAECONNRESET || bytes_received < 0)
    			*temp=L'\0';// **I am not sure if this is necessary or not,but
                                            // the intention is form a null-terminating string.
    #ifdef _UNICODE
    			mbstowcs(temp,recbuf,bytes_received); // I think this it the vital part..right???
                                                                                   // maybe smthg wrong here?
    	return true;
    Last edited by Marc G; November 30th, 2010 at 02:55 AM. Reason: Added code tags

  2. #2
    Join Date
    Nov 2003

    Re: Win32 API multilanguage conversion WCHAR,TCHAR problem?

    HTTP does not deal in TCHAR's - just octects, or char's.

    The char string that you recv will have a particular encoding: http://en.wikipedia.org/wiki/Charact...odings_in_HTML

    You'll then need to convert that into a Windows wchar_t string, typically via MultiByteToWideChar() where the codepage parameter corresponds to the HTTP/HTML encoding that was recv'd.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.