Click here to Skip to main content
16,016,868 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionSign ' is the same as \' ? Pin
George_George23-Nov-07 2:26
George_George23-Nov-07 2:26 
AnswerNOPE Pin
CPallini23-Nov-07 2:39
mveCPallini23-Nov-07 2:39 
GeneralRe: NOPE Pin
George_George23-Nov-07 3:08
George_George23-Nov-07 3:08 
GeneralRe: NOPE Pin
DoomedOne23-Nov-07 3:37
DoomedOne23-Nov-07 3:37 
GeneralRe: NOPE Pin
George_George23-Nov-07 5:13
George_George23-Nov-07 5:13 
GeneralRe: NOPE Pin
toxcct23-Nov-07 3:41
toxcct23-Nov-07 3:41 
GeneralRe: NOPE Pin
George_George23-Nov-07 5:15
George_George23-Nov-07 5:15 
QuestionWhere to put delete[] to prevent memory leaks? Pin
Priya_Sundar22-Nov-07 23:47
Priya_Sundar22-Nov-07 23:47 
hi,

I am using the function ConvertResourceStringIdToLptstr() to assign the value of the TV_INSERTSTRUCT's pszText for the creation/initialization of a TreeCtrl. (or) to convert the 'resource string' into a pointer to a character string.
<br />
LPTSTR COperDialog::ConvertResourceStringIdToLptstr(UINT nResString)<br />
{<br />
	CString strLoad;<br />
	strLoad.LoadString(nResString);<br />
	LPTSTR lpsz = new TCHAR[strLoad.GetLength()+1];<br />
	CHECK_FOR_NULL(lpsz)<br />
	_tcscpy(lpsz,strLoad);<br />
	return lpsz;<br />
}<br />


And the fuction is used in:
<br />
void COperDialog::AddProjectRootItem()<br />
{<br />
	TV_INSERTSTRUCT     curTreeItem;<br />
<br />
	curTreeItem.hParent =TVI_ROOT ;<br />
	curTreeItem.hInsertAfter = TVI_ROOT ;<br />
	curTreeItem.item.iImage = 0;<br />
	curTreeItem.item.iSelectedImage = 0;<br />
<br />
	curTreeItem.item.pszText = ConvertResourceStringIdToLptstr(IDS_PROJECT);<br />
	curTreeItem.item.cchTextMax=15;<br />
<br />
	curTreeItem.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;<br />
	    <br />
	htrProjectRoot = m_Edit->InsertItem(&curTreeItem); <br />
<br />
}<br />


In this situation i am getting memory leaks in ConvertResourceStringIdToLptstr().

So to avoid that where should i insert the delete[]? If i use it inside the function - ConvertResourceStringIdToLptstr() i am not able to get the string displayed!

Kindly give sugesstions!!







Priya Sundar

AnswerRe: Where to put delete[] to prevent memory leaks? Pin
Nelek22-Nov-07 23:57
protectorNelek22-Nov-07 23:57 
GeneralRe: Where to put delete[] to prevent memory leaks? Pin
CPallini23-Nov-07 0:17
mveCPallini23-Nov-07 0:17 
GeneralRe: Where to put delete[] to prevent memory leaks? Pin
Priya_Sundar23-Nov-07 0:42
Priya_Sundar23-Nov-07 0:42 
GeneralRe: Where to put delete[] to prevent memory leaks? Pin
CPallini23-Nov-07 2:08
mveCPallini23-Nov-07 2:08 
GeneralRe: Where to put delete[] to prevent memory leaks? [modified] Pin
Nelek23-Nov-07 2:02
protectorNelek23-Nov-07 2:02 
GeneralRe: Where to put delete[] to prevent memory leaks? Pin
CPallini23-Nov-07 2:18
mveCPallini23-Nov-07 2:18 
GeneralRe: Where to put delete[] to prevent memory leaks? Pin
Nelek23-Nov-07 4:20
protectorNelek23-Nov-07 4:20 
GeneralRe: Where to put delete[] to prevent memory leaks? Pin
CPallini23-Nov-07 5:28
mveCPallini23-Nov-07 5:28 
GeneralRe: Where to put delete[] to prevent memory leaks? Pin
Nelek25-Nov-07 21:22
protectorNelek25-Nov-07 21:22 
GeneralRe: Where to put delete[] to prevent memory leaks? Pin
CPallini25-Nov-07 21:41
mveCPallini25-Nov-07 21:41 
GeneralRe: Where to put delete[] to prevent memory leaks? Pin
Priya_Sundar25-Nov-07 22:34
Priya_Sundar25-Nov-07 22:34 
GeneralRe: Where to put delete[] to prevent memory leaks? Pin
Priya_Sundar23-Nov-07 0:41
Priya_Sundar23-Nov-07 0:41 
AnswerYou don't need such a mess Pin
CPallini23-Nov-07 0:09
mveCPallini23-Nov-07 0:09 
GeneralRe: You don't need such a mess Pin
Priya_Sundar23-Nov-07 0:39
Priya_Sundar23-Nov-07 0:39 
GeneralRe: You don't need such a mess Pin
CPallini23-Nov-07 0:52
mveCPallini23-Nov-07 0:52 
GeneralRe: You don't need such a mess Pin
Priya_Sundar23-Nov-07 1:03
Priya_Sundar23-Nov-07 1:03 
GeneralRe: You don't need such a mess Pin
CPallini23-Nov-07 2:34
mveCPallini23-Nov-07 2:34 

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.