Reputation: 1
BSTR length;
BSTR checkLength = SysAllocString(TEXT("document.getElementsByTagName('tspan').length.toString()"));
HRESULT h = gWebView->stringByEvaluatingJavaScriptFromString(checkLength, &length);
SysFreeString(checkLength);
long longLength;
h = VarI4FromStr(length,0,0,&longLength);
SysFreeString(length);
BSTR index;
long longIndex = longLength - 1;
h = VarBstrFromI4(longIndex,0,0,&index);
The last line VarBstrFromI4 changes the value of index(BSTR) to my desired value but also changes the value of length(BSTR) to the value of index(BSTR). I have been trying to do many options including SysAllocString with index and length but the same problem persists.
Please help.
Upvotes: 0
Views: 591
Reputation: 18507
Once you have called SysFreeString
on a string you should not care about that string anymore. The freed string holds an address internally to deallocated memory which may later be allocated by another string or variable. In this case it just happens that the new string is placed at the same memory address as the old string.
Upvotes: 2