Click here to Skip to main content
15,888,527 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Windows Procedure Pin
Bob Stanneveld21-Sep-05 5:34
Bob Stanneveld21-Sep-05 5:34 
QuestionWhy does a non-blocking socket get blocked when call connect? Pin
alvaro21-Sep-05 4:32
alvaro21-Sep-05 4:32 
QuestionLength of VARIANT V_BSTR Pin
Kreatief21-Sep-05 4:23
Kreatief21-Sep-05 4:23 
AnswerRe: Length of VARIANT V_BSTR Pin
Steen Krogsgaard21-Sep-05 23:51
Steen Krogsgaard21-Sep-05 23:51 
GeneralRe: Length of VARIANT V_BSTR Pin
Kreatief22-Sep-05 0:32
Kreatief22-Sep-05 0:32 
GeneralRe: Length of VARIANT V_BSTR Pin
Steen Krogsgaard22-Sep-05 0:49
Steen Krogsgaard22-Sep-05 0:49 
GeneralRe: Length of VARIANT V_BSTR Pin
Kreatief22-Sep-05 1:10
Kreatief22-Sep-05 1:10 
GeneralRe: Length of VARIANT V_BSTR Pin
Steen Krogsgaard22-Sep-05 1:26
Steen Krogsgaard22-Sep-05 1:26 
Your code got f***ed up because you didn't check the "do not treat <'s as HTML tags" box.

Anyway, you only allocate 500 chars to do the conversion, so it's no wonder that it wont' work for more than 500 chars. And you have a buffer overrun when cnvrtData is more than 500 chars since you don't check for max 500 chars in your for loop. There's no saying what will happen, but you will definitely get your memory screwed up. Furhtermore, you return a pointer to cnvrt which is a stack variable that will go out of scope (and be overwritten) when the function returns.

Why do you move the content of cnvrtData into cnvrtChr? Can't you do the LPCSTR cast directly on cnvrtData? Besides, you should call MultiByteToWideChar with cchWideChar set to zero firt to get the length of the widechar, then allocate it and then convert it:

<br />
int iLength = MultiByteToWideChar(CP_ACP,0,(LPCSTR)cnvrtData,-1,NULL,0);<br />
OLECHAR* cnvrt = new OLECHAR[iLength]; // perhaps iLength+1; MSDN is not clear on wether the terminating NULL is included in the length returned by MultiByteToWideChar<br />
MultiByteToWideChar(CP_ACP,0,(LPCSTR)cnvrtData,-1,cnvrt,iLength; // or iLength+1<br />
return cnvrt<br />


but then you will have to remember to delete cnvrt (the return value from strToWc) with delete[] or you'll leak memory.

Cheers
Steen.

"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
GeneralRe: Length of VARIANT V_BSTR Pin
Steen Krogsgaard22-Sep-05 1:33
Steen Krogsgaard22-Sep-05 1:33 
GeneralRe: Length of VARIANT V_BSTR Pin
Kreatief22-Sep-05 2:37
Kreatief22-Sep-05 2:37 
GeneralRe: Length of VARIANT V_BSTR Pin
Steen Krogsgaard22-Sep-05 2:41
Steen Krogsgaard22-Sep-05 2:41 
QuestionDisplay colour depth - what's the point? Pin
Taka Muraoka21-Sep-05 3:42
Taka Muraoka21-Sep-05 3:42 
AnswerRe: Display colour depth - what's the point? Pin
Chris Losinger21-Sep-05 4:18
professionalChris Losinger21-Sep-05 4:18 
GeneralRe: Display colour depth - what's the point? Pin
Taka Muraoka21-Sep-05 4:33
Taka Muraoka21-Sep-05 4:33 
GeneralRe: Display colour depth - what's the point? Pin
Chris Losinger21-Sep-05 4:39
professionalChris Losinger21-Sep-05 4:39 
GeneralRe: Display colour depth - what's the point? Pin
Taka Muraoka21-Sep-05 5:00
Taka Muraoka21-Sep-05 5:00 
GeneralRe: Display colour depth - what's the point? Pin
Shog921-Sep-05 6:12
sitebuilderShog921-Sep-05 6:12 
GeneralRe: Display colour depth - what's the point? Pin
El Corazon21-Sep-05 6:15
El Corazon21-Sep-05 6:15 
GeneralRe: Display colour depth - what's the point? Pin
Taka Muraoka21-Sep-05 6:23
Taka Muraoka21-Sep-05 6:23 
QuestionInstall Project Pin
el_dude21-Sep-05 3:35
sussel_dude21-Sep-05 3:35 
AnswerRe: Install Project Pin
Blake Miller21-Sep-05 4:13
Blake Miller21-Sep-05 4:13 
QuestionMessage window scrolling Pin
Member 222024521-Sep-05 3:17
Member 222024521-Sep-05 3:17 
AnswerRe: Message window scrolling Pin
David Crow21-Sep-05 3:19
David Crow21-Sep-05 3:19 
GeneralRe: Message window scrolling Pin
ddmcr21-Sep-05 3:54
ddmcr21-Sep-05 3:54 
GeneralRe: Message window scrolling Pin
ddmcr21-Sep-05 3:58
ddmcr21-Sep-05 3:58 

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.