DELETE has an abnormality

zhaozj2021-02-16  58

Related URL http://community.9cbs.net/expert/topic/3160/3160520.xml?temp=.199032 test engineering

Class CNewfree: Public inewfree, public ccomobjectroot, Public CCOMCOCLASS

{

PUBLIC:

CNEWFREE ()}

Begin_COM_MAP (CNewfree)

COM_ITERFACE_ENTRY (INEWFREE)

END_COM_MAP ()

Declare_not_AGGREGATABLE (CNEWFree)

DECLARE_REGISTRY_RESOURCEID (iDR_Newfree)

// inewfreepublic: stdmethod (%) (/ * [in] * / byte ** pbmem);}; ---------------------------------------------------------------------------------------------------------------------- ----- # include

#include

STDMETHODIMP CNEWFREE :: getMem (byte ** pbmem) {cstring * pstr = new cstring ("111111111111); * pbmem = (byte *) PSTR;

Return S_ok;} ===============================================================================================================================================================================================================================================================】 , HWND / * hWndCtl * /, BOOL & / * bHandled * /) {INewFree * pINewFree = NULL; CoCreateInstance (__ uuidof (NewFree), NULL, CLSCTX_INPROC_SERVER, __uuidof (INewFree), (void **) & pINewFree);

BYTE * PBDATA = NULL; PINEWFREE-> GetMem (& PBDATA); CString * pstr = null; pstr = (cstring *) pbdata; delete pstr; // One run here is wrong! ! ! Why ??? Return 0;}

-------------------------------------------------- ---------------------

Error analysis, because WTL's CSTRING is not Virtual, so heap is invalid

-------------------------------------------------- ---------------------------

solution:

Class cmystring {

PUBLIC:

CMYSTRING ()

{

m_str = "";

}

Virtual ~ cmyString ()

{

}

CSTRING M_STR;

}

转载请注明原文地址:https://www.9cbs.com/read-17491.html

New Post(0)