Click here to Skip to main content
15,890,512 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: saving file Pin
trioum25-May-09 1:07
trioum25-May-09 1:07 
GeneralRe: saving file Pin
Rajesh R Subramanian25-May-09 1:23
professionalRajesh R Subramanian25-May-09 1:23 
AnswerRe: saving file Pin
Garth J Lancaster25-May-09 0:10
professionalGarth J Lancaster25-May-09 0:10 
AnswerRe: saving file Pin
Hamid_RT25-May-09 0:59
Hamid_RT25-May-09 0:59 
GeneralRe: saving file [modified] Pin
trioum25-May-09 1:02
trioum25-May-09 1:02 
GeneralRe: saving file Pin
killabyte25-May-09 20:34
killabyte25-May-09 20:34 
QuestionRe: saving file Pin
Maximilien25-May-09 4:56
Maximilien25-May-09 4:56 
QuestionANSI to UTF-8 Pin
Souldrift24-May-09 23:15
Souldrift24-May-09 23:15 
Hi there,

I found a code snippet on the web which converts an ANSI string to UTF-8 format. I implemented it in my own and it works.

<br />
////////////<br />
// to UTF-8<br />
char text[1024]={0};<br />
WCHAR w[1024]={0};<br />
int erg=0;<br />
<br />
strcpy(text, m_pData);<br />
<br />
erg=MultiByteToWideChar(CP_ACP, 0, text, -1, w, sizeof(w) / sizeof(WCHAR)); // ANSI to UNICODE<br />
erg=WideCharToMultiByte(CP_UTF8, 0, w, -1, text, sizeof(text), 0, 0);	    // UNICODE to UTF-8<br />
//<br />
////////////<br />


After that 'text' is UTF-8 formatted just nicely.

Now I was wondering, why doesn´t the following (slightly altered) code not work? I just created a char* instead of char[];

<br />
////////////<br />
// to UTF-8<br />
char* text = new char[1024];<br />
WCHAR w[1024]={0};<br />
int erg=0;<br />
<br />
strcpy(text, m_pData);<br />
<br />
erg=MultiByteToWideChar(CP_ACP, 0, text, -1, w, sizeof(w) / sizeof(WCHAR)); // ANSI to UNICODE<br />
erg=WideCharToMultiByte(CP_UTF8, 0, w, -1, text, sizeof(text), 0, 0);	    // UNICODE to UTF-8<br />
//<br />
////////////<br />


Thanks,

Souldrift
AnswerRe: ANSI to UTF-8 Pin
tolw25-May-09 1:00
tolw25-May-09 1:00 
AnswerRe: ANSI to UTF-8 Pin
Nibu babu thomas25-May-09 2:02
Nibu babu thomas25-May-09 2:02 
GeneralRe: ANSI to UTF-8 Pin
Souldrift25-May-09 2:34
Souldrift25-May-09 2:34 
GeneralRe: ANSI to UTF-8 Pin
tolw25-May-09 2:56
tolw25-May-09 2:56 
Questionerror LNK2019: unresolved external symbol "long __cdecl _com_dispatch_method Pin
pandit8424-May-09 23:14
pandit8424-May-09 23:14 
AnswerRe: error LNK2019: unresolved external symbol "long __cdecl _com_dispatch_method Pin
Stuart Dootson25-May-09 1:42
professionalStuart Dootson25-May-09 1:42 
QuestionHEAP CORRUPTION DETECTED! Pin
susanne124-May-09 23:01
susanne124-May-09 23:01 
AnswerRe: HEAP CORRUPTION DETECTED! Pin
CPallini24-May-09 23:19
mveCPallini24-May-09 23:19 
GeneralRe: HEAP CORRUPTION DETECTED! Pin
susanne124-May-09 23:50
susanne124-May-09 23:50 
QuestionRe: HEAP CORRUPTION DETECTED! Pin
CPallini25-May-09 0:03
mveCPallini25-May-09 0:03 
AnswerRe: HEAP CORRUPTION DETECTED! Pin
susanne125-May-09 0:13
susanne125-May-09 0:13 
GeneralRe: HEAP CORRUPTION DETECTED! Pin
Garth J Lancaster25-May-09 0:18
professionalGarth J Lancaster25-May-09 0:18 
GeneralRe: HEAP CORRUPTION DETECTED! Pin
CPallini25-May-09 0:25
mveCPallini25-May-09 0:25 
QuestionRe: HEAP CORRUPTION DETECTED! Pin
CPallini25-May-09 0:27
mveCPallini25-May-09 0:27 
AnswerRe: HEAP CORRUPTION DETECTED! Pin
susanne125-May-09 0:32
susanne125-May-09 0:32 
GeneralRe: HEAP CORRUPTION DETECTED! Pin
Stuart Dootson25-May-09 1:49
professionalStuart Dootson25-May-09 1:49 
JokeRe: HEAP CORRUPTION DETECTED! Pin
Rajesh R Subramanian25-May-09 1:57
professionalRajesh R Subramanian25-May-09 1:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.