Click here to Skip to main content
15,910,211 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCreating derived type from a base class template Pin
Skippums13-Mar-09 6:00
Skippums13-Mar-09 6:00 
AnswerRe: Creating derived type from a base class template Pin
Stuart Dootson13-Mar-09 6:06
professionalStuart Dootson13-Mar-09 6:06 
GeneralRe: Creating derived type from a base class template Pin
Skippums13-Mar-09 6:15
Skippums13-Mar-09 6:15 
GeneralRe: Creating derived type from a base class template Pin
Stuart Dootson13-Mar-09 6:40
professionalStuart Dootson13-Mar-09 6:40 
GeneralRe: Creating derived type from a base class template Pin
Skippums13-Mar-09 8:12
Skippums13-Mar-09 8:12 
GeneralRe: Creating derived type from a base class template Pin
Stuart Dootson13-Mar-09 14:02
professionalStuart Dootson13-Mar-09 14:02 
GeneralRe: Creating derived type from a base class template Pin
Skippums19-Mar-09 9:40
Skippums19-Mar-09 9:40 
QuestionMultiByteToWideChar crashes out on longer strings [modified] Pin
RichardBrock13-Mar-09 4:45
RichardBrock13-Mar-09 4:45 
I've got a code segment below that converts the block of chars read in from an RSS XML file and converts it to the unicode equivalent using a code page (the code page ID is determined beforehand by scanning for the the encoding ID in the XML).

Sometimes it works, sometimes it crashes the application. I'm using the buffer requirement returned by 'MultiByteToWideChar' to allocate the buffer required (+1 because the block of chars I'm passing does not include the 0 terminator). What's really odd is that on small strings it works fine, but on a 216 character string it crashes. If I extend the buffer allocation by 1 then it works all the time. I should not have to kludge buffer allocation to make things work.

int nSizeReq = MultiByteToWideChar(m_nCPID,0,(const char* m_pChars,nBlockLength,0,0);
TCHAR* pszConverted = new TCHAR[nSizeReq+1];
_tcsnset(pszConverted,0,nSizeReq+1);
MultiByteToWideChar(m_nCPID, 0, (const char*)m_pChars,nBlockLength, pszConverted, nSizeReq);
//up to here it always works, but the next step crashes because pszConverted has damage
//past its memory allocation
CString strConverted = pszConverted

Any ideas why this could be happening?

ps. it runs just great in debug, and if I run it in release mode whilst in visual studio it also works. Run the release by itself and *boom*

[edit]
Coded in C++ (MFC application) using Visual Studio 2008
Unicode is defined
Testing on Vista.

modified on Friday, March 13, 2009 10:51 AM

AnswerRe: MultiByteToWideChar crashes out on longer strings Pin
led mike13-Mar-09 5:37
led mike13-Mar-09 5:37 
GeneralRe: MultiByteToWideChar crashes out on longer strings Pin
RichardBrock13-Mar-09 6:22
RichardBrock13-Mar-09 6:22 
QuestionRe: MultiByteToWideChar crashes out on longer strings Pin
led mike13-Mar-09 7:40
led mike13-Mar-09 7:40 
AnswerRe: MultiByteToWideChar crashes out on longer strings Pin
RichardBrock13-Mar-09 8:00
RichardBrock13-Mar-09 8:00 
GeneralRe: MultiByteToWideChar crashes out on longer strings Pin
led mike13-Mar-09 8:41
led mike13-Mar-09 8:41 
AnswerRe: MultiByteToWideChar crashes out on longer strings Pin
Akt_4_U13-Mar-09 5:39
Akt_4_U13-Mar-09 5:39 
GeneralRe: MultiByteToWideChar crashes out on longer strings Pin
RichardBrock13-Mar-09 6:26
RichardBrock13-Mar-09 6:26 
Questionget the font of my control and set it with an other (the face name) Pin
MrKBA13-Mar-09 4:26
MrKBA13-Mar-09 4:26 
AnswerRe: get the font of my control and set it with an other (the face name) Pin
Code-o-mat13-Mar-09 5:15
Code-o-mat13-Mar-09 5:15 
GeneralRe: get the font of my control and set it with an other (the face name) Pin
MrKBA13-Mar-09 5:30
MrKBA13-Mar-09 5:30 
GeneralRe: get the font of my control and set it with an other (the face name) Pin
Code-o-mat13-Mar-09 5:39
Code-o-mat13-Mar-09 5:39 
GeneralRe: get the font of my control and set it with an other (the face name) Pin
MrKBA13-Mar-09 5:47
MrKBA13-Mar-09 5:47 
GeneralRe: get the font of my control and set it with an other (the face name) Pin
Code-o-mat13-Mar-09 5:57
Code-o-mat13-Mar-09 5:57 
GeneralRe: get the font of my control and set it with an other (the face name) Pin
MrKBA13-Mar-09 6:29
MrKBA13-Mar-09 6:29 
QuestionRe: get the font of my control and set it with an other (the face name) Pin
led mike13-Mar-09 5:41
led mike13-Mar-09 5:41 
AnswerRe: get the font of my control and set it with an other (the face name) Pin
MrKBA13-Mar-09 5:51
MrKBA13-Mar-09 5:51 
AnswerRe: get the font of my control and set it with an other (the face name) Pin
Code-o-mat13-Mar-09 5:52
Code-o-mat13-Mar-09 5:52 

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.