CTabCtrl:
添加TAB:
............................
CString title = "TAB1";
CString lparamText = .......
        TC_ITEM tItem;
        tItem.mask = TCIF_TEXT | TCIF_PARAM | TCIF_IMAGE;
tItem.pszText = (LPSTR)title.GetBuffer();
title.ReleaseBuffer();
tItem.lParam = reinterpret_cast<DWORD>(new CString(lparamText));
tItem.cchTextMax = strlen(tItem.pszText);
mTab.InsertItem(0,&tItem);
.........................
获取TAB 的ITEM的LPARAM:
        ....................
CString *pString = reinterpret_cast<CString*>(tItem.lparam);
CString g = pString->GetBuffer();  //在RELEASE下这一行导致CRASH ,
pString->ReleaseBuffer();
return g;

解决方案 »

  1.   

    那样不行的 CString*不能直接转成LPSTRlz的代码中主要错误好像大都是ReleaseBuffer之后 仍然使用GetBuffer返回的指针
    比如
    tItem.lParam   =   reinterpret_cast <DWORD> (new   CString(lparamText)); 
    tItem.cchTextMax   =   strlen(tItem.pszText);不过个人觉得还不至于在拷贝pString-> GetBuffer();的时候会出错啊CString   g   =   pString-> GetBuffer();     //在RELEASE下这一行导致CRASH   , 
    pString-> ReleaseBuffer(); 
    return   g;
    这几句直接改
    return *pString;看看
      

  2.   

    tItem.pszText指向了一个局部的内存块(由于title是局部变量),所以我推测很可能是内存越界访问造成的问题。
    另外,不得不说,楼主对于CString的使用方式确实不值得提倡,完全违背了CString的设计意图。而且程序中的强转也使用过度,象CString   g   =   pString-> GetBuffer();这样的拷贝完全没有必要使用非常量指针,如楼上所说直接返回*pString就足够了。