tvi.lParam = (LPARAM) add0.c_str();
this is the problem. tvi.lParam
is a pointer type.
FROM MSDN :
LPARAM This type is declared in WinDef.h as follows: typedef LONG_PTR LPARAM;
what is a add0
? I guess it is a local variable. If the function return, this add0
var will be deconstructed, and tvi.lParam
is pointed to the inter buff of string add0
, and now this inter buff is freed, so tvi.lParam
points to the garbage.