struct SRegion
{
int width;
int height;
};typedef struct tagMyFormat
{
char* name;
SRegion* sRegion;
UINT State;
UINT Image;
tagMyFormat(char* ch)
{
name = new char[sizeof(ch)+1];
strcpy(name,ch);
sRegion = new SRegion[sizeof(SRegion)];
}
~tagMyFormat()
{
if(name)
{
delete name;
name = NULL;
}
if(sRegion)
{
delete sRegion;
sRegion = NULL;
}
}
}MyFormat;void CTreeControl::OnCopy() 
{
// TODO: Add your command handler code here
UINT format = RegisterClipboardFormat("MyFormat");
if(OpenClipboard())
{
HGLOBAL hGlobal;
EmptyClipboard();
hGlobal = GlobalAlloc(GMEM_DDESHARE,sizeof(MyFormat));
MyFormat* pMyFormat =(MyFormat*)GlobalLock(hGlobal);
pMyFormat->Image =1;
pMyFormat->State = GetItemState(GetSelectedItem(),TVIS_STATEIMAGEMASK); pMyFormat->name = new char[GetItemText(GetSelectedItem()).GetLength()];
strcpy(pMyFormat->name,LPCSTR(GetItemText(GetSelectedItem()))); pMyFormat->sRegion = new SRegion[sizeof(SRegion)];
pMyFormat->sRegion->height = 2;
pMyFormat->sRegion->width = 3;

GlobalUnlock(hGlobal);
SetClipboardData(format,hGlobal);
CloseClipboard(); //delete pMyFormat->name;
//delete pMyFormat->sRegion;
}
}我定义的结构MyFormat中有指针,而且该指针在构造函数中分配内存,在析构函数中释放内存
    
    我现在要用剪切板进行复制粘贴(oncopy,onpaste),在oncopy中,全局内存hGolbal中保存的是一个指针,(pMyFormat中的)非指针变量state,image可以直接赋值,但是指针变量name,SRegion得new出来(不new运行就错误),   
    
  最后,oncopy中进行delete的话就会运行错误,
       不进行delete能够运行,但是这样的话就造成内存泄露。   
      
  这该怎么解决阿