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

    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)
    Code:
    #define _UNICODE
    #define UNICODE
    #define RECBUFF 100000
    .
    .
    .
    .
    .
    .
    
    bool KNetCon::WriteToScr(HWND hEditCtl)
    {
       // ----clear screen in edit
    	::SendMessage(hEditCtl,WM_SETTEXT,0,(LPARAM)L"");
    	DWORD writtenBytes;
    	int bytes_sent;
    	int bytes_received=SOCKET_ERROR;
    	char *sendbuf="GET / HTTP/1.0 \r\n\r\n";
    
    	bytes_sent=send(m_socket,sendbuf,strlen(sendbuf),0);
    
    	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]
    
    
    	while(1)
    	{
    		i++;
    		bytes_received=recv(m_socket,recbuf,RECBUFF,0);
                                                       //***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.
    
    			break;
    		}
    		else
    		{
    #ifdef _UNICODE
    			mbstowcs(temp,recbuf,bytes_received); // I think this it the vital part..right???
                                                                                   // maybe smthg wrong here?
    #endif
    			temp+=bytes_received;
    
    		}
    	}
    
    	::SendMessage(hEditCtl,WM_SETTEXT,0,(LPARAM)(LPVOID)&wrecbuf);
    	InvalidateRect(hEditCtl,NULL,TRUE);
    	UpdateWindow(hEditCtl);
    
    	return true;
    }
    Last edited by Marc G; November 30th, 2010 at 03:55 AM. Reason: Added code tags

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    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.
    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

    gg

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
  •  





Click Here to Expand Forum to Full Width

Featured