用new分配的内存到底该不该delete掉?
部分代码如下:
HKEY hRoot,hSub;
hRoot = GetSelectedRoot();
if(RegOpenKeyEx( hRoot, strPath, NULL, KEY_QUERY_VALUE, &hSub))
{
*pResult = 0;
return;
}
while ( RegEnumKeyEx( hSub,
dwIndex,
NULL,
&dwSize,
NULL,
NULL,
NULL,
NULL) != ERROR_NO_MORE_ITEMS)
{
char* pBuffer = new char[dwSize++];
RegEnumKeyEx( hSub, dwIndex, pBuffer,
&dwSize,NULL, NULL, NULL, NULL);
tvis.item.pszText = pBuffer;
m_KeyTree.InsertItem( &tvis);
dwIndex++;
dwSize = 0;
}
RegCloseKey( hSub);
其中有两个问题,一、有人告诉我pBuffer应delete,请大家计论一下;
二、当hSub下没有子键时,仍会在TreeCtrl中插入一个子结点,为
什么?