ramrocket
asked on
SendMessage CString
I am sending this from a thread:
...
AfxGetMainWnd()->SendMessa ge(WM_MY_M ESSAGE, 0 , new CString(L"Delete Me") );
I am wondering if this creates a memory leak even doing a delete.
LRESULT ::OnMyMessage(WPARAM wp, LPARAM lp)
{
CString *pString = (CString *) lp;
delete pString, pString=0;
}
...
AfxGetMainWnd()->SendMessa
I am wondering if this creates a memory leak even doing a delete.
LRESULT ::OnMyMessage(WPARAM wp, LPARAM lp)
{
CString *pString = (CString *) lp;
delete pString, pString=0;
}
ASKER
can you explain how this cause a memory leak? how to use LPCTSTR pointer in this case?
thanks,
thanks,
what happens if you just send
AfxGetMainWnd()->SendMessa ge(WM_MY_M ESSAGE, 0 ,CString(L"Delete Me") ); <==
MAHESH
AfxGetMainWnd()->SendMessa
MAHESH
ASKER
the reason I use new because a pointer to CString can be casted to LPARAM. the above usage of CString on the stack will give an error: cannot convert from CString to LPARAM
>> how to use LPCTSTR pointer in this case?
ie.
SendMessage(WM_MY_MESSAGE, 0 ,(LPARAM) (LPCTSTR)"Delete Me") <== now handle this in your function as LPCTSTR
MAHESH
ie.
SendMessage(WM_MY_MESSAGE,
MAHESH
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this works!
It's better to use LPCTSTR pointer OR just at destruction delete the CString object..no need to ue new operator.
MAHESH